cujojs / meld

AOP for JS with before, around, on, afterReturning, afterThrowing, after advice, and pointcuts
Other
644 stars 65 forks source link

when object instace is advised? #20

Closed enginespot closed 11 years ago

enginespot commented 11 years ago
if(this instanceof advised) {
                // shamelessly derived from https://github.com/cujojs/wire/blob/c7c55fe50238ecb4afbb35f902058ab6b32beb8f/lib/component.js#L25
                context = objectCreate(orig.prototype);
                callOrig = function (args) {
                    return applyConstructor(orig, context, args);
                };

            } 

for the above code , I do not understand , when this instance will be advised

I test by the follow code

var user=new User();
meld.before(User.prototype, 'fun1', function() {
    console.log('hello fun1');
    });
    meld.before(user, 'fun1', function() {
      console.log('hello new fun1');
    });

but did not capture user or User.prototype as advised instance

enginespot commented 11 years ago

got it

Advised = meld.before(Advised, verifyContext);
new Advised();