Created
April 6, 2011 10:24
-
-
Save dsingleton/905442 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
(function(src) { | |
document.body.appendChild(document.createElement('script')).setAttribute('src', src); | |
})(prompt("Script URL to load", "http://example.com/script.js")); | |
// You could drop the self executing function now src is at the end of the line, it's just as easy to edit. |
Fair point, I was getting overly code-golfy. Not that passing document in helps, you're right.
Nothing against local vars, but i like the style of passing args, and avoiding a var declaration. All very cosmetic. Just re-writing it now to be cleaner and shorter.
I like the pattern of passing in variables for dependency injection to make functions more reusable/testable, but not sure there's a benefit in this case. You only care about the local scope inside the function, so a local variable is probably the best solution. Fore!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What's wrong with local variables? How is passing in a document any shorter? Surely it makes the overall code longer even if the function is shorter?