Javasrcipt 定义一个可以为函数添加多个方法Methods

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


var Methods = new Function();


Methods.addMethod('checkName',function(){
  let arg = Array.prototype.slice.call(arguments);
  console.log(arg);
})





Methods.addMethod('checkEmail',function(){
  let arg = Array.prototype.slice.call(arguments);
  console.log(arg);
})

var m = new Methods();
m.checkName()

 

你可能感兴趣的:(普通文章)