Created
October 30, 2009 16:38
-
-
Save jakearchibald/222507 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
<!-- 1. Simple, usual case with callback --> | |
<script type="text/javascript"> | |
Glow("2").load("core", "widgets").ready(function (glow) { | |
// core & widgets loaded & dom ready | |
glow.widgets.doodle(); | |
}); | |
</script> | |
<!-- 2. 'Application Pattern'. Allows glow instance to be easily used in a wider but not global scope --> | |
<script type="text/javascript"> | |
(function() { | |
var glow = new Glow("2.3").load("core", "widgets").ready(init); | |
function init() { | |
// core & widgets loaded & dom ready | |
glow.widgets.doodle(); | |
} | |
})(); | |
</script> | |
<!-- 3. User sets global in callback --> | |
<script type="text/javascript"> | |
(function() { | |
Glow("2.3.4").load("core", "widgets").ready(function (G) { | |
// core & widgets loaded & dom ready | |
window.glow = G; | |
init(); | |
}); | |
})(); | |
function init() { | |
glow.widgets.doodle(); | |
} | |
</script> | |
<!-- 4. Callback for glow modules loading --> | |
<script type="text/javascript"> | |
Glow("2.3.4").load("core", "widgets").loaded(function (glow) { | |
// core & widgets loaded but dom may not be ready | |
}); | |
</script> | |
<!-- 5. Callback is always required, due to asynchronous loading --> | |
<script type="text/javascript"> | |
// can't detect missing callback here | |
var glow = new Glow("2.3.4").load("core", "widgets"); | |
// fails because modules not done downloading yet. | |
glow.widgets.doodle(); | |
</script> | |
<!-- 6. Documentation is different --> | |
<script type="text/javascript"> | |
/** | |
@name Glow#widgets.doodle | |
*/ | |
// ... | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment