Skip to content

Instantly share code, notes, and snippets.

@iansym
Created December 6, 2010 22:35
Show Gist options
  • Save iansym/731114 to your computer and use it in GitHub Desktop.
Save iansym/731114 to your computer and use it in GitHub Desktop.
can we on-demand js using pubsub and namespaced functions/methods/whatever
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>test</title>
<script src="jquery-1.4.4.js"></script>
<script src="jquery.pubsub.js"></script>
<script>
// namespace
(window.ns || (window.ns = {}) )
// this is a stub that will do something later
ns.stub = function() {
var args = Array.prototype.slice.call(arguments);
console.log('args',args);
// we want to call this function again when it exists
subscribe('stub/loaded', function() {
ns.stub.apply(this,args);
});
// load the script w/ delay for testing purposes
setTimeout(function() {
jQuery.getScript('stub.js', function(){
publish('stub/loaded');
});
}, 2500);
};
</script>
</head>
<body>
<script>
ns.stub("this","is","a","test");
</script>
</body>
</html>
(window.ns || (window.ns = {}));
ns.stub = function() {
console.log(arguments);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment