【发布时间】:2012-11-12 02:08:24
【问题描述】:
我正在使用 jQuery,但我对 JavaScript 还是很陌生。我正在实现一个对象如下:
MyObject = {
properties : [{}],
resetProperties: function resetProperties() { this.properties = [{}] }
};
正如您在上面的代码中看到的那样,我可以通过运行 MyObject.resetProperties() 来重置 properties,但是为了做到这一点,我声明了 两次 次 [{}] 变量。我应该如何在不重复该代码的情况下完成相同的事情?
更新
我尝试执行以下操作:
MyObject = {
properties : this.propertiesDefault,
resetProperties : function resetProperties() { this.properties = [{}] },
propertiesDefault: [{}]
};
但我收到“TypeError: invalid 'in' operand MyObject.properties”,但我不确定这是正确的继续方式。
【问题讨论】:
标签: javascript jquery object methods properties