链式封装与调用
var CheckObject = function(){}; CheckObject.prototype = function(){ checkName:function(){ // code return this; }, checkEmail:function(){ // code return this; }, checkPassword:function(){ // code return this; } } //使用 var Check = new CheckObject() Check.checkName().checkEmail().checkPassword();
原型上链式添加方法与链式调用
Function.prototype.addMethod = function(name,fn){ this.prototype[name] = fn; return this; } var Methods = function(){}; Methods.addMethod("checkName",function(){ // code }).addMethod("checkEmail",function(){ // code }) // 使用 var Check = new Methods() Check.checkName()
-----------------------------------------------------------------------小二给我来二两轮子!