所以我知道有很多方法可以模拟继承和其他OO功能。我选择了一个用于我的项目,我想知道我是否可以创建一个实例并添加内容并保持它(在括号内)。 请考虑以下事项:
function BaseClass(){
<this.stuff here>
}
function SubClass(){
this.superClass = BaseClass();
this.superClass();
<this.other stuff here>
}
myObj = new SubClass();
所以myObj是SubClass的一个实例。我可以像myObj一样添加东西:
myObj.blah = "funtimes";
我想要的是能够将内容添加到“实例”并将其组织在大括号中,就像构造函数一样。 psuedo代码如:
myObj = new SubClass() {
var blah = "funtimes"
<more instance specific stuff here>
}
这样的事情可能吗? 谢谢!