所以,假设我有以下脚本:
var hey = {
foo: 1,
bar: 2,
baz: 3,
init: function(newFoo){
this.foo = newFoo;
return this;
}
}
hey.check = function(){
alert('yeah, new function');
}
基本上,我可以调用new hey.init(999)并获取一个设置为 999 的新hey变量。hey.foo但是当我这样做时,hey.init(999).check()不再定义。有没有办法模仿脚本,但允许 newhey具有扩展的变量/函数?
编辑:更改hey.check()为hey.init(999).check()
对此感到抱歉...