I have a function constructor which creates an object with a function, say, do_it:
function do_it_maker() {
this.do_it = function() { /* do something */ };
this.other_do = function() { /* do anything else */ };
}
And I want to create a wrapper for a do_it_maker object enriching the do_it behaviour through parasitic inheritance:
function do_it_maker_wrapper() {
var do_it_obj = new do_it_maker();
do_it_obj.do_it_original = do_it_obj.do_it;
do_it_obj.do_it = function() {
do_it_obj.do_it_original();
/* smth_else */
}
return do_it_obj;
}
var do_it_obj = new do_it_maker_wrapper();
do_it_obj.do_it(); // Reimplemented version.
do_it_obj.other_do(); // Untouched.
My question is, will the do_it_obj.do_it() call cause a recursive call? or the reference to the original do_it function is still alive?
I have found related questions here in StackOverflow but I have read contradictory answer about if the method must be cloned or not.
So, what will it happen? In case the reference becomes recursive after changing do_it, which is the most understandable and with the fewest amount of code required way of cloning that method? I'm a C++ and not-happy-with-just-copy-paste-code guy and some Javascript features look still obscure to me (I'm not clumpsy though, you can do it a bit hard).
self? That doesn't seem to work.newoperator when your factory functionsreturnobjects anyway.