Created
March 26, 2009 22:54
-
-
Save isaacs/86422 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
// How awful is this approach? Really awful? Not awful? | |
// Cuz it seems not awful, and actually really convenient. | |
// Note how MyComponent has a single instance of YUI(), | |
// but without having to wrap the whole thing in the YUI call. | |
// This means that MyComponent can be extended later on, | |
// and still use the same single instance of YUI. | |
MyComponent = (function () { | |
var myYUI = null | |
var load = function (fn) { | |
if (myYUI && fn) return fn(); | |
myYUI || YUI().use( | |
'log', 'lang', 'node', 'event', 'dom', 'json', | |
function (y) { | |
myYUI = y; | |
return fn(); | |
}); | |
return false; | |
}; | |
var doSomething = function (asdf) { | |
if (!myYUI) throw new Error("Not loaded yet!"); | |
// do something with the myYUI instance. | |
}; | |
return { load:load, doSomething:doSomething }; | |
})(); | |
MyComponent.load(function () { | |
MyComponent.doSomething("foo"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment