Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deferred's valueOf should clean up _props and _super #4

Open
Mr0grog opened this issue Jul 26, 2010 · 0 comments
Open

Deferred's valueOf should clean up _props and _super #4

Mr0grog opened this issue Jul 26, 2010 · 0 comments

Comments

@Mr0grog
Copy link

Mr0grog commented Jul 26, 2010

It seems like not deleting or resetting deferred._super and deferred._props after valueOf() is done could lead to odd behavior, e.g. if someone should happen to hold a reference to the deferred created by def("MyClass") and do something that invokes valueOf() a second (or third, or fourth…) time, unexpected things could happen to the prototype.

While this example is a bit contrived who knows what odd things might occur in real use:

def ("Person") ({
    init: function(name){
        this.name = name;
    },

    speak: function(text){
        alert(text || "Hi, my name is " + this.name);
    }
});

var NinjaDef = def ("Ninja");
NinjaDef << Person ({
    init: function(name){
        this._super();
    },

    kick: function(){
        this.speak("I kick u!");
    }
});

Person ({
    guns: true
});

// This is a bit contrived, but... who knows what odd thing could happen to cause valueOf() to run
NinjaDef + 5;

var ninjy = new Ninja("JDD");
console.log("ninjy.name: ", ninjy.name); // should be JDD
console.log("ninjy.guns: ", ninjy.guns); // Ninjas don't use guns!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant