function Animal(name) {
this.name = name;
this.getName = function() {
return this.name;
}
this.setName = function(name) {
this.name = name;
this._valueChangeHandler('name');
}
}
Animal.prototype = {
onChange: function(valueName, fun) {
this["_" + valueName + "ChangeHandlers"] = this["_" + valueName + "ChangeHandlers"] || [];
this["_" + valueName + "ChangeHandlers"].push(fun);
},
_valueChangeHandler: function(valueName) {
var o = this["_" + valueName + "ChangeHandlers"];
if (o) {
for (var i = 0, n = o.length; i < n; i++) {
var methodName = "get" + valueName.charAt(0).toUpperCase() + valueName.slice(1);
o[i](this[methodName]());
}
}
}
}
var a = new Animal('zhangsan');
a.onChange('name', function(o) {
console.log("1.my name is " + o);
});
a.onChange('name', function(o) {
console.log("2.my name is " + o);
});
a.setName("zhangsanfeng");
var a = new Animal('zhangsan');
a.onChange('name', function(o) {
});
a.onChange('name', function(o) {
});
a.setName("zhangsanfeng");
function Animal(name) {
this.name = name;
this.getName = function() {
return this.name;
}
this.setName = function(name) {
this.name = name;
this._valueChangeHandler('name');
}
}
Animal.prototype = {
onChange: function(valueName, fun) {
this["_" + valueName + "ChangeHandlers"] = this["_" + valueName + "ChangeHandlers"] || [];
this["_" + valueName + "ChangeHandlers"].push(fun);
},
_valueChangeHandler: function(valueName) {
var o = this["_" + valueName + "ChangeHandlers"];
if (o) {
for (var i = 0, n = o.length; i < n; i++) {
var methodName = "get" + valueName.charAt(0).toUpperCase() + valueName.slice(1);
o[i](this[methodName]());
}
}
}
}
var a = new Animal('zhangsan');
a.onChange('name', function(o) {
console.log("1.my name is " + o);
});
a.onChange('name', function(o) {
console.log("2.my name is " + o);
});
a.setName("zhangsanfeng");function Animal(name) {
this.name = name;
this.getName = function() {
return this.name;
}
this.setName = function(name) {
this.name = name;
this._valueChangeHandler('name');
}
}
Animal.prototype = {
onChange: function(valueName, fun) {
this["_" + valueName + "ChangeHandlers"] = this["_" + valueName + "ChangeHandlers"] || [];
this["_" + valueName + "ChangeHandlers"].push(fun);
},
_valueChangeHandler: function(valueName) {
var o = this["_" + valueName + "ChangeHandlers"];
if (o) {
for (var i = 0, n = o.length; i < n; i++) {
var methodName = "get" + valueName.charAt(0).toUpperCase() + valueName.slice(1);
o[i](this[methodName]());
}
}
}
}
var a = new Animal('zhangsan');
a.onChange('name', function(o) {
console.log("1.my name is " + o);
});
a.onChange('name', function(o) {
console.log("2.my name is " + o);
});
a.setName("zhangsanfeng");function Animal(name) {
this.name = name;
this.getName = function() {
return this.name;
}
this.setName = function(name) {
this.name = name;
this._valueChangeHandler('name');
}
}
Animal.prototype = {
onChange: function(valueName, fun) {
this["_" + valueName + "ChangeHandlers"] = this["_" + valueName + "ChangeHandlers"] || [];
this["_" + valueName + "ChangeHandlers"].push(fun);
},
_valueChangeHandler: function(valueName) {
var o = this["_" + valueName + "ChangeHandlers"];
if (o) {
for (var i = 0, n = o.length; i < n; i++) {
var methodName = "get" + valueName.charAt(0).toUpperCase() + valueName.slice(1);
o[i](this[methodName]());
}
}
}
}
var a = new Animal('zhangsan');
a.onChange('name', function(o) {
console.log("1.my name is " + o);
});
a.onChange('name', function(o) {
console.log("2.my name is " + o);
});
a.setName("zhangsanfeng");
function Animal(name) {
this.name = name;
this.getName = function() {
return this.name;
}
this.setName = function(name) {
this.name = name;
this._valueChangeHandler('name');
}
}
Animal.prototype = {
onChange: function(valueName, fun) {
this["_" + valueName + "ChangeHandlers"] = this["_" + valueName + "ChangeHandlers"] || [];
this["_" + valueName + "ChangeHandlers"].push(fun);
},
_valueChangeHandler: function(valueName) {
var o = this["_" + valueName + "ChangeHandlers"];
if (o) {
for (var i = 0, n = o.length; i < n; i++) {
var methodName = "get" + valueName.charAt(0).toUpperCase() + valueName.slice(1);
o[i](this[methodName]());
}
}
}
}
var a = new Animal('zhangsan');
a.onChange('name', function(o) {
console.log("1.my name is " + o);
});
a.onChange('name', function(o) {
console.log("2.my name is " + o);
});
a.setName("zhangsanfeng");function Animal(name) {
this.name = name;
this.getName = function() {
return this.name;
}
this.setName = function(name) {
this.name = name;
this._valueChangeHandler('name');
}
}
Animal.prototype = {
onChange: function(valueName, fun) {
this["_" + valueName + "ChangeHandlers"] = this["_" + valueName + "ChangeHandlers"] || [];
this["_" + valueName + "ChangeHandlers"].push(fun);
},
_valueChangeHandler: function(valueName) {
var o = this["_" + valueName + "ChangeHandlers"];
if (o) {
for (var i = 0, n = o.length; i < n; i++) {
var methodName = "get" + valueName.charAt(0).toUpperCase() + valueName.slice(1);
o[i](this[methodName]());
}
}
}
}
var a = new Animal('zhangsan');
a.onChange('name', function(o) {
console.log("1.my name is " + o);
});
a.onChange('name', function(o) {
console.log("2.my name is " + o);
});
a.setName("zhangsanfeng");