canjs / can-map-define

Define rich attribute behavior
https://canjs.com/doc/can-map-define.html
MIT License
3 stars 2 forks source link

Instances of a Map using define are overwriting the parent's define #24

Closed kylegifford closed 7 years ago

kylegifford commented 7 years ago

Any values/getters specified in a child define seem to be overwriting the parent for other instances. Here are a couple of examples:

Even though Step2's prototype's define is not the same object as that of StepVm, it gets a shallow copy of the define object, so the define for 'foo' is the same object.

This is fixed if you use DefineMap (see http://jsbin.com/sokowerazi/1/edit?js,output).

bmomberger-bitovi commented 7 years ago

Interesting note: you might never notice this bug if you were only overwriting value defines with other value defines, because such an object sets up the defaults for the class while the define object itself still suffers from mutability to subclasses. I.e., if I create object A with a value property def, then subclass A into B overwriting the property def, new A() will still be correct, but extending A into C after that, without overwriting the property def, will give new C() the value from B.