Created
June 4, 2012 23:39
-
-
Save rwaldron/2871510 to your computer and use it in GitHub Desktop.
jQuery.each() w/ fat arrow
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
/** | |
* | |
* paste this code into: | |
* | |
* http://traceur-compiler.googlecode.com/git/demo/repl.html | |
* | |
* | |
*/ | |
if (!window.jQuery) { | |
document.head.appendChild( | |
document.createElement("script").{ | |
src = "http://code.jquery.com/jquery.js"; | |
} | |
); | |
} | |
jQuery.each([ "foo", "bar", "baz" ], (i, item) => { | |
console.log(item); | |
}); |
Yeah, looks like jQuery hasn't loaded yet...
I actually typed this in by hand, so by the time I got to jQuery.each
the top was parsed and executed.
This seems to work for a "drop in" paste...
if ( !("jQuery" in window) ) {
document.head.appendChild(
document.createElement("script").{
src = "http://code.jquery.com/jquery.js";
onload = function() {
window.jQuery.each([ "foo", "bar", "baz" ], (i, item) => {
console.log( item );
});
};
}
);
}
thx, it works.
but I never saw the keyword 'let' in JavaScript. I am confused.
let
is like var
but its block scoped instead of lexically scoped. It's new in E6
TBH, this isnt a very interesting use of let
- I'm also jut getting accustomed to these new language features
Simple let
:
if (true) {
let a = "alpha";
}
console.log( "a" in this ); // false
I updated the snippet above... the script
variable was actually unnecessary
got it. thx. I am ready to learn sth. about E6 too.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I pasted the code into repl.html, but it says
repl(10, 1): jQuery is not defined