我有一个构造函数:
var Constructor = function(property) {
this.property = property;
this.changeProperty = function() {
*by clicking should change the property*
}
}
然后我创建了一个对象:
var newObject = new Constructor(propertyValue);
newObject.changeProperty();
那么,是否可以更改已创建对象的属性值?
答案 0 :(得分:0)
那么,是否可以更改已创建的属性值 对象
是的,试试
lundi 27 juin 2016 10:15
并将其作为
调用var Constructor = function(property) {
this.property = property;
var self = this;
this.changeProperty = function( newProperty ) {
self.property = newProperty;
}
}
答案 1 :(得分:0)
var Constructor = function(property) {
this.property = property;
this.changeProperty = function(newProp) {
this.property = newProp
}
}
var newObject = new Constructor("oldProp");
newObject.property //oldPropery
newObject.property = "newproperty"
newObject.property//"newproperty"