风之优雅z

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
Function.prototype.before = function (func){
    var self = this;
    return function (){
        if(func.apply(this, arguments) === false){
            return false;
        }
        return self.apply(this, arguments);
    }
}
Function.prototype.after = function (func){
    var self = this;
    return function (){
        var ret = self.apply(this, arguments);
        if(ret === false){
            return false;
        }
        func.apply(this, arguments);
        return ret;
    }
}

var a = function (){console.log('a function') };
var c = a.before(function (){console.log('before');}).after(function (){console.log('after')})
c();

原文:http://www.w3cfuns.com/thread-5597323-1-1.html

posted on 2014-11-18 11:05  风之优雅z  阅读(184)  评论(0编辑  收藏  举报