> From: Andrew Dupont <[email protected]> > JJB has it mostly right. When Sam wrote Object.extend (which was originally > Object.prototype.extend), it didn't use hasOwnProperty; my guess is that Sam > didn't know about it, because most of us were JavaScript amateurs back in the > day, including myself. When I joined the project over a year later, I > remember discussing this problem and discovering that Safari 2.0 didn't > support hasOwnProperty.
For an example of creating a workaround for lack of hasOwnProperty see: https://github.com/bestiejs/spotlight.js/blob/master/spotlight.js#L189 > That, plus the hazard of changing implementation behavior, led us to leave > things as they were. If I were writing Prototype's Object.extend from > scratch, I'd definitely want it to copy "own" properties only. > MooTools also has an Object.extend() with a bonus that it tries to avoid IE bugs with for..in over shadowed Object.prototype properties. I've used similar private `extend()` functions that mimic the Prototype/MooTools behavior and remember in at least one of my projects running into problems when attempting to make extend() only iterate over own properties. > Anyway, I'm in favor of standardizing Object.extend in ES6, but in a way that > considers only "own" properties (including private names, if so desired). I > don't think ES6 should copy the exact behavior of Prototype's (flawed) > version of Object.extend. Whether that takes the form of a method named > "Object.extend" or a .{ operator? well, that's less important to me, but my > vote is for the former. The former, Object.extend, will be hard to add if it is to only iterate over `own` properties, as I think it should, because Prototype/MooTools and others add their own Object.extend, without checking if the method exists, paving any existing method with their own implementation. This will create inconsistencies between pages/third-party code that use Prototype/MooTools and those that don't. Introducing an operator has the advantage of not being overwritten/mucked-with and allows for shorter/fluid syntax. I <3 monocle operator! - JDD _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

