SOURCE

Function.prototype.before = function(fn) {
    var _this = this; // 用来保存调用这个函数的引用,如func_1调用此函数,则_this指向func_1

        console.log(this)
        console.log('arguments', arguments)
    return function() { // 返回一个函数,这个函数包含原函数和新函数,原函数指的是func_1,新函数指的是fn

        console.log('arguments 2', arguments)

        fn.apply(this, arguments); // 执行新函数
        return _this.apply(this, arguments); // 执行原函数
    }
}

Function.prototype.after = function(fn) {
    var _this = this;
    return function() {
        var r = _this.apply(this, arguments); // 先执行原函数,也就是func_1
        fn.apply(this, arguments); // 再执行新函数
        return r;
    }
}
 
var func_1 = function() {
    console.log("2")
}

func_1.before(function(){console.log('a b c')})('cc ')

// func_1(); // 输出1、2、3
console 命令行工具 X clear

                    
>
console