Created
December 6, 2010 22:35
-
-
Save iansym/731114 to your computer and use it in GitHub Desktop.
can we on-demand js using pubsub and namespaced functions/methods/whatever
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
<!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> |
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
(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