Created
June 16, 2010 21:16
-
-
Save ghinch/441282 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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