//=============================================================
//====================定义一个静态对象以及静态方法推荐=================
var CMyString = new Object();
Object.extend(CMyString, {
HelloWord : function(){
alert("Helllo world!");
}
}
);
CMyString.HelloWord();
//=============================================================
//====================定义一个对象的两种方法推荐=================
//1.利用Prototype中提供的Class定义一个新的对象类型,然后通过initialize初始化
var ClassCreateObject = Class.create();
ClassCreateObject.prototype = {
initialize: function(_sInfo) {
alert("init me!["+_sInfo+"]");
this.sInfo = _sInfo;
},
sInfo: "default",
getInfo: function(){
return"I'm Class.create!["+this.sInfo+"]!";
}
};
var oClassCreateObject = new ClassCreateObject("1");
alert(oClassCreateObject.getInfo());
//2.采用最原始的方式通过Function定义一个新的对象类型,在function中初始化
var NewObject = function(_sInfo) {
alert("init me!["+_sInfo+"]");
this.sInfo = _sInfo;
};
NewObject.prototype = {
getInfo: function(){
return"I'm new Object["+this.sInfo+"]!";
}
};
var oNewObject = new NewObject("2");
alert(oNewObject.getInfo());