1 定义原型模式
var pro = function() {
this.index = 2;
this.init();
};
pro.prototype = {
init:function() {
alert(this.index);
alert('ok');
},
test:function(){
alert(‘test’);
}
};
var obj = new pro (); // 生成对象
2 json 形式
var json =
{
'index':2,
'func_a': function()
{
alert(this.index);
}
};
json.func_a(); // 直接调用
3 静态类模式
var Common = {};
Common.test = function(text) {
Alert(‘ok’);
}
Common.test(); // 直接调用
4 普通类模式
var Valifrm = function(name)
{
this.formName = name;
this.errMsg = new Array();
this.addErrorMsg = function(str)
{
this.errMsg.push(str);
}
}
Var vali = new Valifrm(); // 生成对象Vali.addErrorMsg(); // 再调用