面向对象的JavaScript
类:
function DelegateObject(){
var obj = new Object();
类:
function DelegateObject(){
var obj = new Object();
obj.value = "";
obj.FormatString = null;
obj.toString = function _toString(){
if(obj.FormatString != null)
return this.FormatString(this.Value);
else
return this.Value;
}
return obj;
}
var obj = new DelegateObject();
委托:
function DelegateObject(){
var obj = new Object();
obj.value = "";
obj.FormatString = null;
obj.toString = function _toString(){
if(obj.FormatString != null)
return this.FormatString(this.Value);
else
return this.Value;
}
return obj;
}
function ConvertToString(value){
return "Result:" + value;
}
var obj = new DelegateObject();
obj.Value = "Hello World!";
obj.FormatString = ConvertToString;
document.write(obj.toString());