0
    MyClass = function(params) {
     if(params.init){ 
       params.init.call(this, this.Myobject); 
     }
    };
    Myclass.prototype.Myobject = { someKeys: 'someStuff'}

I wrote a JavaScript-class with a prototype.object. When I call the class I have the possibility to edit this object:

var myClass = new MyClass({ init: function (Myobject){Myobject.foo = 'bla'}});

and I run this with:

params.init.call(this, this.Myobject);

So this overrides the prototype. Init should rewrite the Myobject for the instance myClass, other instances should use the Prototype if they get no init function.

TEST
  • 67
  • 7
  • Could you show us how `MyClass` is defined? – georg Apr 05 '16 at 09:40
  • do you mean this? (Edit in the Question) – TEST Apr 05 '16 at 10:33
  • @TEST: no, wee need to know what `/* do something */` is exactly. – Bergi Apr 05 '16 at 10:35
  • 2
    Can you put that together into a single executable test case and explain how what you get and what you expect differ? It's really hard to follow what is going on when you're just showing us fragments of code. http://stackoverflow.com/help/mcve – Quentin Apr 05 '16 at 10:36
  • 1
    possible duplicate of https://stackoverflow.com/questions/4425318/javascript-object-members-that-are-prototyped-as-arrays-become-shared-by-all-cla – Bergi Apr 05 '16 at 10:37

1 Answers1

0

so after i got no answer i asked my trainer. My problem was very simple... so i created the myobject as a prototype. yeah so it will always rewrite the prototype. the solution i used is easy:

i created the myobject with this.myobject = {bla:foo}

so now it isnt part of the prototype but every instance will create this object new.

TEST
  • 67
  • 7