2011/10/6 Brendan Eich <bren...@mozilla.com> > On Oct 5, 2011, at 9:02 PM, John J Barton wrote: > > Trait.create() parallels Object.create() and I gather that > Trait.compose() resembles proposed Object.extend(). I wonder if the > traits.js 'parallel-universe' could be applied to Trait.resolve(). In my > experience resolve() isn't needed, but academic work on traits suggests > otherwise, so it might be a good thing to investigate. > > Tom Van Cutsem should weigh in. >
A bit late, but nonetheless: Trait.compose() does not resemble Object.extend(). Trait.override() does. (Trait.compose will flag name clashes in src and dest objects, Trait.override automatically overrides existing properties in dest with those from src). The parallel to Trait.resolve() would be some operation that can rename/remove properties. For example: var dest = {x:1,y:2}; > Object.rename(dest, {x: "a"}) {a:1,y:2} > Object.rename(dest, {foo: "a"}) {x:1,y:2} > Object.remove(dest, ["x", "y"]) {} The traits philosophy is that, when merging objects, you want to see name clashes flagged as exceptions (to prevent inadvertent overriding). That's why an additional operation like Trait.resolve() is needed to deliberately avoid those conflicts. I gather than the philosophy of Object.extend is that src always overrides dest properties. That's a different philosophy, but that's fine. An orthogonal issue is whether Object.extend / Trait.override should be functional or imperative. For traits.js I deliberately chose a functional API. Traits can be used in several different compositions, and you don't want any of those compositions to side-effect your traits. For Object.extend, the common use case may be different. Cheers, Tom
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss