These are chat archives for canjs/canjs

Jul 2018
Jul 30 2018 08:38
Hi @justinbmeyer , sorry for the late reply. I was on holiday for two weeks. The issue you pointed to #3864 was an interesting read, but it's not really business critical for us at the moment.
Jul 30 2018 19:40
I have a very odd problem (using Can 3) where any time I initialize an object with properties (e.g., new MyModel({foo: 'bar'})), any values I specify for those properties actually get copied to the prototype and used as the default value for any new instances of those objects going forward. I'm investigating to try to figure out why this might be happening, and the simple jsbin I set up to try to reproduce it didn't have the issue, but has anyone seen anything like this?
Jul 30 2018 20:11
Specifically, what I'm finding is that in define.setup (can-define.js:835 in 1.5.6), the line map[prop] = value modifies both this._data[prop] and this.constructor.prototype[prop].
Jul 30 2018 23:43

Aha, I got a repro in the jsbin! Run this code:

const Test = can.DefineMap.extend('Test', {
    title: {value: 'test'}

// Comment out this line to see "expected" behavior
console.log(`Prototype: ${Test.prototype.title}`);

console.log(`Default title: ${new Test().title}`);
console.log(`Overridden title: ${new Test({title: 'what'}).title}`);
console.log(`Default title: ${new Test().title}`);

The console output is:

"Prototype: test"
"Default title: test"
"Overridden title: what"
"Default title: what"
Jul 30 2018 23:51
For some reason, getting a property from the prototype causes later sets of that property to modify both the instance and the prototype, so that later objects will all use that value as their default values going forward.