Skip to content

Instantly share code, notes, and snippets.

@ericf
Forked from kara-ryli/definition.js
Created March 12, 2011 06:40
Show Gist options
  • Select an option

  • Save ericf/867093 to your computer and use it in GitHub Desktop.

Select an option

Save ericf/867093 to your computer and use it in GitHub Desktop.

Revisions

  1. ericf revised this gist Mar 12, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion definition.js
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ var MyClass = Y.Base.create('my-class', Y.Base, [], {
    _mergeProps: function (value, prop) {
    var cur = this.get(prop);
    if (Y.Lang.isUndefined(cur)) {
    cur = this.constructor.ATTRS[prop].value;
    this.reset(prop); // will rest to { test: true } for this instance instead of always using the static default values
    }
    return Y.merge(cur, value);
    }
  2. @kara-ryli kara-ryli created this gist Mar 10, 2011.
    19 changes: 19 additions & 0 deletions definition.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    var MyClass = Y.Base.create('my-class', Y.Base, [], {
    _mergeProps: function (value, prop) {
    var cur = this.get(prop);
    if (Y.Lang.isUndefined(cur)) {
    cur = this.constructor.ATTRS[prop].value;
    }
    return Y.merge(cur, value);
    }
    }, {
    ATTRS: {
    dict: {
    value: {
    foo: 'bar',
    test: false
    },
    setter: '_mergeProps'
    }
    }
    });
    6 changes: 6 additions & 0 deletions implementation.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    var instance = new MyClass({
    dict: {
    test: true
    }
    });
    instance.get('dict'); // { foo: 'bar', test: true }