-1
这是我从属性的哈希创建对象:如何重用对象构造函数?
var object = new function (data) {
var self = this;
self.property = data.property;
self.anotherProperty = data.anotherProperty;
self.method = function() { return 'something'; }
self.update = function (newData) {
//what is here ?
//i could have written:
self.property = newData.property;
self.anotherProperty = newData.anotherProperty;
//but why not reuse the constructor?
}
};
我不知道如何再利用这个功能(构造函数)来更新哈希从一个对象。 这样:
object.update(newData)
将从newData
哈希以同样的方式是在构造函数中完成更新当前对象的属性。
嘿,好思考你转身倒挂问题,冷静这允许该功能保持匿名。 – Dziamid 2012-08-03 10:16:09