What it should do: Calling method on instance should morph "constructor prototype" in different prototype but keeps instance (and all other instances) alive
What I have (written so far):
var differentPrototypeObj = {
test: function() {
console.log("it is working");
}
}
var F = function() {
};
F.prototype = {
changeMyConstructorPrototype: function() {
this.constructor.prototype = Object.create(differentPrototypeObj); // doesnt work, but I though it should
this.constructor.prototype = differentPrototypeObj; // doesnt work, but I though it should
F.prototype = whatever; // dont want to do this because F is being inherited somewhere and it
}
};
Testing:
var f = new F();
f.changeMyconstructorPrototype();
console.log(f.test); // want this to be function, but is undefined
console.log(f.changeMyConstructorPrototype); // want this to be undefined, but is still accessible
I guess in my code is this.constructor.prototype
but I cant figure out what to use instead.
EDIT - Usage:
It is just concept that comes in my mind. I use it in Angular 1.5 service. Service itself is used to drive form wizard. User can change various things in form and few of them causes large changes across entire form wizard.
This large change must keep instance alive, but changes a lot of behavior (mostly input validations, properties counts and inputs visibility) in both (forward and backward) directions in form wizard.
I create multiple dependent instances and return them from service. Then when I user changes "core" inputs, prototype is changed for the instance parent which does everything else for you.
There could be chosen different approach but I chose this one as experimental and interesting.