azendal / neon

EcmaScript Code Writting DSL
http://azendal.github.io/neon
MIT License
43 stars 19 forks source link

Instance variables share the same reference across instances (acting like class variables) #12

Open jchayan opened 6 years ago

jchayan commented 6 years ago

For example:

Class('MyClass')({
    prototype: {
        property: [ ]
    }
});

var instance1 = new MyClass();
var instance2 = new MyClass();

instance1.property.push(1);

console.log(instance2.property):

Not good!

jchayan commented 6 years ago

Pinned: https://github.com/azendal/neon/blob/master/neon.js#L148

@azendal I think we should use Object.assign in there

azendal commented 6 years ago

its you. all variables are references and arrays and objects are shared across instances due to the prototype pattern.