js对象(三)

js使用祖先元素

//js的祖先元素 Function
Function.prototype.addMethod=function(name,fn){
    this[name]=fn;
}
var methods = new Function();
methods.addMethod("checkUser",function(){
    console.log(111);
});
methods.addMethod("checkEmail",function(){
    console.log(2222);
});
methods.checkUser();
methods.checkEmail();
//=========================================================
//js链式操作
Function.prototype.addMethod = function(name,fn){
    this[name]=fn;
    return this;
}
var methods = new Function();
methods.addMethod("checkuser",function(){
    console.log(1111);
    return this;
}).addMethod("checkname",function(){
    console.log(2222);
    return this;
});
methods.checkuser().checkname();
//===========================================================
Function.prototype.addMethod=function(name,fn){
    this.prototype[name]=fn;
    return this;
}
var methods = Function();
methods.addMethod("checkname",function(){
    console.log(33333);
}).addMethod("checkuser",function(){
    console.log(4444);
});
var m = new methods();
m.checkname();
m.checkuser();

你可能感兴趣的:(js对象(三))