Object.define ==> Object.mixin??

Nathan Wall nathan.wall at live.com
Wed Dec 12 23:26:40 PST 2012

On Dec 11, 2012, at 10:19 AM, Andrea Giammarchi wrote:

> Agreed, getOwnPropertyNames is way more appropriate if the topic is: use
> all ES5 features for mixins too.

I totally agree as well.

> Also, the Nicolas example is potentially disaster prone, not in that
> specific form, but in the way a getter with private scope access could be.

> Imagine many objects using that specific object as mixin with that name getter,
> if there was a setter too the first one that will use it will overwrite the
> returned value for all other objects.

> I think propertie swith getters and setters will cause as many headaches as
> objects and arrays in function prototypes did before already but hey, if you
> know what you are doing, I believe there's no other solution for "universally
> capable mixin method"

Possibly, however, symbols are the solution to the headache right? With the introduction of symbols, we're able to easily tie internal state to objects rather than scope.

    var $name = new Symbol();

    var Person = {
        get name() {
            return this[$name];
        set name(value) {
            this[$name] = value;

    var John = Object.mixin({ }, Person);
    John.name = 'John';

    var Sam = Object.mixin({ }, Person);
    Sam.name = 'Sam;

    John.name; // => 'John'
    Sam.name;  // => 'Sam'


More information about the es-discuss mailing list