//v2目的:为函数扩展原型方法,好处是省略prototype这个长单词。
Function.prototype.method = function(name, fn, isOverRide){
//防止修改原型的共有结构,保险的方法是确定没有时才添加
//如果强制覆盖,则需要指定第三个参数为true
if(!this.prototype[name] || isOverRide==true){
this.prototype[name]=fn;
}
//else{ throw 'Method Exists!'; } //怎么报错呢?
//不存在是否需要报错呢?感觉应该报错的
return this;
}
F12 show Console: