打字稿 - 有没有办法像新功能名称()'喜欢在javascript中

时间:2017-10-30 00:58:23

标签: javascript typescript

我想知道我是否有一个声明为:

的函数
function foo(){
  var x = 10;
}

如何在javascript中使用某些内容:

var foo1 = new foo();// In javascript to create an object type of a function
var xOfFoo = foo1.x;

创建函数的对象类型,并在typescript中访问它的属性?

1 个答案:

答案 0 :(得分:0)

您可以在TypeScript中执行此操作。在这种情况下,class MainWindow(QMainWindow, Ui_MainWindow): def __init__(self, *args, **kwargs): QMainWindow.__init__(self, *args, **kwargs) self.setupUi(self) self.setUpMainUiFunction() def setUpMainUiFunction(self): self.actionOpen.triggered.connect(self.OpenDialog) self.Button_LoadPhoto.clicked.connect(self.OpenDialog) open = QAction(QIcon("icons/open.bmp"), "open", self) save = QAction(QIcon("icons/save.bmp"), "save", self) NormalCursor = QAction(QIcon("icons/cursor-normal.png"), "NormalCursor", self) CrosshairCursor = QAction(QIcon("icons/crosshair.png"), "CrosshairCursor", self) self.TopToolBar.addAction(open) self.TopToolBar.addAction(save) self.LeftToolBar.addAction(NormalCursor) self.LeftToolBar.addAction(CrosshairCursor) # self.TopToolBar.actionTriggered[QAction].connect(self.toolbtnpressed) def OpenDialog(self): options = QFileDialog.Options() options |= QFileDialog.DontUseNativeDialog PicturePath = QStandardPaths.standardLocations(QStandardPaths.PicturesLocation)[0] filenames, _ = QFileDialog.getOpenFileNames(self, "Open File", PicturePath, "JPEG File (*.png)", options=options) for filename in filenames: pixmap = QPixmap(filename) self.showPicture(pixmap) self.statusbar.showMessage("Successfully Loaded: {}".format(filename)) def showPicture(self, picture): sub = QMdiSubWindow(self) loadPicture = LoadPicture(picture, sub) sub.setWidget(loadPicture) sub.setObjectName("Load_Picture_window") sub.setWindowTitle("New Photo") self.mdiArea.addSubWindow(sub) sub.show() sub.resize(picture.size()) loadPicture.log.MousePixmapSignal.connect(self.updatePixel) def updatePixel(self, point, color): self.UserInput_PixelValue_X.setText("{}".format(point.x())) self.UserInput_PixelValue_Y.setText("{}".format(point.y())) self.UserInput_PixelValue_R.setText("{}".format(color.red())) self.UserInput_PixelValue_G.setText("{}".format(color.green())) self.UserInput_PixelValue_B.setText("{}".format(color.blue())) 将引用函数的范围,因为函数声明不在类中。

this