On Sun, Nov 13, 2011 at 2:36 AM, Axel Rauschmayer <a...@rauschma.de> wrote: > It depends on what kind of `extends` you mean: > - Inheritance: Even though data being kept in prototypes is rare, it’s > usually better to chain prototypes even when ignoring aliasing problems (no > redundant properties, instanceof works transitively). Performance > degradation should be negligible due to internal optimizations. > - Merging objects: Shallow copy is the way to go.
Perhaps you mean: 'it depends on the use of the object returned by |extends()|'. But I don't understand your categories. Mine: Object-like: you want to use the returned object directly. I think a dev imagines extend() as a kind of initialization, a merger operation: var a = merge(b,c,d); In this case you do not expect deep copy, you expect shallow, reference copy. If I change d.color, I expect that a.color is changed. Or rather, I would say that a dev would not be surprised at this behavior. Class-like: you want to use the returned object indirectly, to create other objects via Foo.prototype/new Foo or similar operation. Here we are operating on two levels. In the abstract level we are combining objects to define factory; in the concrete level we are creating objects based on that factory. The data on the inputs to the abstract level are -- at most -- relevant as initial values for the concrete level. You want something like deep copy. As I mentioned elsewhere, the Object-like merge can be used (with care) on collections of methods then applied to Foo.prototype. That's how we get along now: one operation covers both cases just not always robustly. jjb _______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss