javascript AOP

Function.prototype.bind = function(b) {
    var a = this;
    return function() {
        a.apply(b, arguments)
    }
};
Function.prototype.once = function() {
    var b = false,
        a = this;
    return function() {
        if (b) {
            return
        } else {
            b = true;
            a.apply(this, arguments)
        }
    }
};
Function.prototype.before = function(b) {
    var a = this;
    return function() {
        if (b.apply(this, arguments) == false) {
            return false
        }
        return a.apply(this, arguments)
    }
};
Function.prototype.after = function(b) {
    var a = this;
    return function() {
        var c = a.apply(this, arguments);
        if (c === false) {
            return false
        }
        b.apply(this, arguments);
        return c
    }
};
String.prototype.hasString = function(f) {
    if (typeof f == "object") {
        for (var d = 0, g = f.length; d < g; d++) {
            if (!this.hasString(f[d])) {
                return false
            }
        }
        return true
    } else {
        if (this.indexOf(f) != -1) {
            return true
        }
    }
};
原文地址:https://www.cnblogs.com/human/p/3494073.html