Skip to content

Instantly share code, notes, and snippets.

@sdesai
Forked from ghinch/gist:444093
Created June 18, 2010 20:48
Show Gist options
  • Save sdesai/444213 to your computer and use it in GitHub Desktop.
Save sdesai/444213 to your computer and use it in GitHub Desktop.
YUI.add('root-cls', function (Y) {
Y.Base._buildCfg.aggregates.push('getClassAttrs');
Y.rootClass = Y.Base.create('root-class', Y.Base, [], {
someInstanceMethod : function () {}
}, {
ATTRS : {
test : {
validator : Y.Lang.isBoolean
}
}
});
Y.rootExt = Y.Base.create('root-ext', Y.Base, [], {}, {
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.rootClass, [Y.rootExt], {}, {
ATTRS : {
foo : {
validator : Y.Lang.isNumber
},
bar : {
validator : Y.Lang.isString
}
}
});
console.log('class method: ', mainClass.getClassAttrs)
console.log('class instanceof: ', new mainClass() instanceof Y.rootClass);
console.log('class attrs: ', mainClass.getClassAttrs());
var mySubClass = Y.Base.create('my-subclass', mainClass, [Y.rootExt], {}, {
ATTRS : {
baz : {
validator : Y.Lang.isBoolean,
value : false
}
}
});
console.log('subclass method: ', mySubClass.getClassAttrs)
console.log('subclass instanceof: ', new mySubClass() instanceof Y.rootClass);
console.log('subclass attrs: ', mySubClass.getClassAttrs());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment