Created
January 17, 2011 22:04
-
-
Save sebmarkbage/783586 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| ART; // inherits ART.SVG | |
| ART.Shape; // inherits ART.SVG.Shape | |
| var surface = new ART(100, 100); // inherits ART.SVG | |
| new ART.Shape().inject(surface); // inherits ART.SVG.Shape | |
| var CustomClass = new Class({ | |
| Extends: ART.Shape | |
| }); // inherits ART.SVG.Shape | |
| ART.switch(ART.Canvas); | |
| ART; // inherits ART.Canvas | |
| ART.Shape; // inherits ART.Canvas.Shape | |
| var surface = new ART(100, 100); // inherits ART.Canvas | |
| new ART.Shape().inject(surface); // inherits ART.Canvas.Shape | |
| new CustomClass().inject(surface); // Error! inherits ART.SVG.Shape | |
| // Problem occurs even if only one mode is permitted per context, | |
| // since ART.Canvas mode is not guaranteed to be defined while | |
| // CustomClass is loading. | |
| // The problem is not specific to on-the-fly context switching but | |
| // extension modes as well. |
This file contains hidden or 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
| ART.Class = function(name, obj){ | |
| var parent = obj.Extends; | |
| for (var mode in ART.modes){ | |
| obj.Extends = ART[mode][parent]; | |
| ART[mode][name] = new Class(obj); | |
| } | |
| ART[name] = ART[ART.currentMode][name]; | |
| }; | |
| ART.Class('CustomClass', { | |
| Extends: 'Shape' | |
| }); | |
| ART.Canvas.CustomClass; // inherits ART.Canvas.Shape | |
| // ...OR... | |
| ART.Shape = new Class({ | |
| initialize: function(){ | |
| this.realObj = new ART.Mode.Shape(); | |
| }, | |
| method: function(){ | |
| return this.realObj.method.apply(this.realObj, arguments); | |
| } | |
| // Doesn't create proxy methods for unknown extensions on custom modes | |
| // Slow indirection | |
| // Ugly | |
| }); | |
| // ...OR... | |
| // ECMAScript Harmony style dynamic module loaders with IoC support | |
| // The global ART is set for this module load context | |
| loadModule('CustomClass', { ART: ART.Canvas }, function(CustomClass){ | |
| CustomClass; // inherits ART.Canvas | |
| // do stuff | |
| }); | |
| // General question... What does CustomClass require in a packager? | |
| // Just ART. It have to assume a mode exists during initialization time. | |
| // The module loader is always required to set the global ART mode. | |
| // Not just for edge cases where on-the-fly context switching is required. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment