Created
July 17, 2013 09:52
-
-
Save apaatsio/6019247 to your computer and use it in GitHub Desktop.
Load JavaScript functions synchronously just-in-time. This is just a concept. This is not ready and I haven't even tried running this.
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
myObject = | |
myFunction: loadFunction 'myModule/myFunction', this |
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
loadFunction = (path, self) -> | |
(args...) -> | |
functionDoesntExist = not window.myNamespace?.myModule?.myFunction? | |
if functionDoesntExist | |
scriptSrc = loadScriptSrc path | |
scriptTag = """<script type="text/javascript">#{scriptSrc}</script>""" | |
document.write scriptTag | |
# TODO bind self | |
window.myNamespace.myModule.myFunction args... | |
loadScriptSrc = (path) -> | |
pathElements = path.split('/') | |
# TODO get rid of dependency on _ | |
_.reduce( | |
pathElements | |
(currentPath, pathElement) -> currentPath[pathElement] | |
loadableFunctions | |
) | |
loadableFunctions = | |
myModule: | |
myFunction: "window.myNamespace.myModule.myFunction = function() {};" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment