首页 > 解决方案 > JavaScript 有条件地添加方法

问题描述

我正在阅读“JavaScript: The Good Parts”并且遇到了这个令人困惑的代码片段

 Function.prototype.method = function( name, func){
    if (!this.prototype[name]){
        this.prototype[name] = func;
    }
};

书中说“一种防御技术是仅在已知方法缺失时才添加方法。” 我对此的问题是:

感谢您的时间

标签: javascriptfunctionmethods

解决方案


推荐阅读