美文网首页
2019-08-05 拓展现有函数

2019-08-05 拓展现有函数

作者: 冰已凋零 | 来源:发表于2019-08-05 14:03 被阅读0次

    定义、声明的函数

    function b() {
        console.log(arguments);
    }
    
    var b = function (base) {
        return function () {
            base(arguments);
        }
    }(b)
    

    拓展原型链上的方法

    // 使用lodash遍历Object
    var _ = require("lodash");
    
    function b() {
    
    }
    
    b.prototype.add = function () {
        console.log(arguments);
    }
    
    _.forEach(b.prototype, function(executiveFun, functionName) {
        b[functionName] = function (base) {
            return function () {
                base(arguments);
            }
        }(b[functionName])
    });
    
    var c = new b();
    c.add(1,2,3,4);
    

    相关文章

      网友评论

          本文标题:2019-08-05 拓展现有函数

          本文链接:https://www.haomeiwen.com/subject/qpcmdctx.html