js设计模式---面向对象

var CheckObject = function(){};
CheckObject.prototype = {
	checkName:function(){
		//validate code
		return this;
	}
	checkEmail:function(){
		//validate code
		return this;
	}
	checkPassword:function(){
		//validate code 
		return this;
	}
}

//use the method

var a = new CheckObject();
a.checkName().checkPassword().checkEmail();

//bind on function

Function.prototype.addMethod = function(name,fn){
	this[name] = fn;
}

//use

var methods = new Function();
methods.addMethod('checkName',function(){
	//validate code
	return this;
});
methods.checkName();


你可能感兴趣的:(js设计模式---面向对象)