我没有得到这方面的确切解决方案......请帮助大家......提前致谢。
function Variable(initVal, onChange) {
debugger;
this.val = initVal; //Value to be stored in this object
this.onChange = onChange; //OnChange handler
//This method returns stored value
this.GetValue = function () {
return this.val;
}
//This method changes the value and calls the given handler
this.SetValue = function (value) {
this.val = value;
this.onChange();
}
}
var myVar = new Variable(10, function () { alert("Value changed!"); });
alert(myVar.GetValue());
myVar.SetValue(12);
alert(myVar.GetValue());