Created
June 18, 2010 19:26
-
-
Save ghinch/444093 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) { | |
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