Skip to content

Instantly share code, notes, and snippets.

@ghinch
Created June 16, 2010 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghinch/441282 to your computer and use it in GitHub Desktop.
Save ghinch/441282 to your computer and use it in GitHub Desktop.
YUI.add('root-cls', function (Y) {
// Have to add the method name to be aggregated down the inheritance chain
Y.Base._buildCfg.aggregates.push('getClassAttrs');
Y.rootClass = Y.Base.create('root-class', Y.Base, [], {
someInstanceMethod : function () {}
}, {
ATTRS : {
test : {
validator : Y.Lang.isBoolean
}
},
getClassAttrs : function () {
var attrs = {},
c = this.prototype.constructor;
while (c) {
Y.mix(attrs, c.ATTRS, true);
c = (c.superclass ? c.superclass.constructor : null);
}
return attrs;
}
});
}, '1.0', {requires : ['base']});
YUI().use('root-cls', function (Y) {
var mainClass = Y.Base.create('main-class', Y.Base, [Y.rootClass], {}, {
ATTRS : {
foo : {
validator : Y.Lang.isNumber
},
bar : {
validator : Y.Lang.isString
}
}
});
console.log(mainClass.getClassAttrs());
var mySubClass = Y.Base.create('my-subclass', Y.Base, [mainClass], {}, {
ATTRS : {
baz : {
validator : Y.Lang.isBoolean,
value : false
}
}
});
console.log(mySubClass.getClassAttrs());
console.log(new mySubClass());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment