Skip to content

single AOP #8

@lvleihere

Description

@lvleihere
Function.prototype.before = function(beforeFn) {
    const _this = this;
    return function() {
        beforeFn.call(this, arguments);
        _this.call(this, arguments);
    };
};

Function.prototype.after = function(afterFn) {
    const _this  = this;
    return function() {
        _this.call(this, arguments);
        afterFn.call(this, arguments);
    };
}

function originFn() {
    console.log(1);
}

originFn
    .before(function() {
        console.log(2);
    })
    .after(function() {
        console.log(3);
    })();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions