Created
October 21, 2011 22:16
-
-
Save lsmith/1305121 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
// For Y.Foo | |
// Class extensions that will be used in the base class | |
function ExtA() {} | |
... | |
Y.namespace('Foo').ExtA = ExtA; | |
// Base Class definition | |
function FooBase() {} | |
... | |
Y.Foo.Base = Y.Base.create('foo', Y.Base, [FooBase, Y.Foo.ExtA]); | |
Y.Foo = Y.mix( Y.Base.create('foo', Y.Foo.Base, []), Y.Foo, true ); | |
// Optional class extensions | |
function ExtB() {} | |
... | |
Y.Foo.ExtB = ExtB; | |
Y.Base.mix(Y.Foo, [ExtB]); | |
// If there aren't any other class extensions used to define the base class | |
Y.namespace('Foo').Base = Y.Base.create('foo', Y.Base, [], { proto }, { statics }); | |
Y.Foo = Y.mix( Y.Base.create('foo', Y.Foo.Base, []), Y.Foo, true ); | |
// Alternate for constructing the base class with extensions: | |
Y.Foo.Base = Y.Base.create('foo', Y.Base, [], { proto }, { statics }); | |
Y.Base.mix(Y.Foo.Base, [ Y.Foo.ExtA ]); | |
Y.Foo = Y.mix( Y.Base.create('foo', Y.Foo.Base, []), Y.Foo, true ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently, this pattern runs into trouble when the extensions that will define core behavior include static properties. Base.create only aggregates ATTRS for Base subclasses and ATTRS and HTML_PARSER (maybe a few more) for Widget subclasses onto the generated class.
It's awkward and not intuitive to refer to statics on a class extension, and Base.create (as of this writing) looks only on the superclass axis for what statics to aggregate, so there's no easy way to keep the extensions decoupled from the Base.create()d class implementation. Today, you must use the alternate pattern to copy statics from the extensions, but this means changes in the extension need to be mirrored in the code that consumes it (ick).
This issue is being tracked here: http://yuilibrary.com/projects/yui3/ticket/2531567