0
返回我有一个对象的原型的函数调用getComponent
返回this.components[name]
使用Javascript - 按功能
function Foo()
{
this.components = {"Scripts": [...], "Sprites": [...], "States": {...}, etc };
}
Foo.prototype.getComponent = function(name)
{
return this.components[name];
}
然后,我有一些代码,获取组件并将其设置为别的东西的参考ASIGN值。 ...
var foo = new Foo();
foo.getComponent("Sprites") = [];
这显然引发了Uncaught ReferenceError: Invalid left-hand side in assignment
。
有无论如何设置返回值的值?我不想直接访问对象变量:foo.components.Sprites = []
。
由于提前,
大卫
您可以像'getComponent'方法一样创建'setter'方法来更新值 –