I would like to do some stuff after before or after new has run.
function F() {
this.init = function () { alert(0) }
}
F.prototype.init = function () { alert(1) }
new F().init(); // Will not run mine, because on new F(), init is reassigned within the class.
I understand I can create my own method function Create() { new F().init() }
But I was wondering if there is a way to hook into the new Function call ?
I hope you understand what I mean.
newis not a function call,F()is. You could do something like this, replacingFwith your own delegate.If you want a utility function to do this kind of thing:
or use one of many frameworks/libraries (ExtJS, jQuery, Prototype) that provides this stuff.
Following discussion
This can start you off on what you’re trying to do, but I don’t guarantee it works in all situations or implementations (only tested on V8). You could pass the context in which F exists as an additional parameter, or make sure you apply/bind/call
extendwith it.