2019-08-05 拓展现有函数

2019-08-05  本文已影响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);
上一篇 下一篇

猜你喜欢

热点阅读