Last active
August 23, 2016 19:22
-
-
Save pha-ias/57dd71eaeb6d2e43e531e02617129f9a to your computer and use it in GitHub Desktop.
Revisions
-
pha-ias revised this gist
Aug 23, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ // ES6 and beyond // ------------------------- // String Literal // ------------------------- var someString = `Something` -
pha-ias created this gist
Aug 23, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,132 @@ // ES6 and beyond // ------------------------- //String Literal // ------------------------- var someString = `Something` typeof someString // Multiline support var someText = ` Something really long and not interesting ` var desc = "awesome" // Exception when declaring a string?! var someText = ` Something ${awesome} long and not interesting `; // VM446:3 Uncaught ReferenceError: awesome is not defined(…)(anonymous function) @ VM446:3 var someText = ` Something ${desc} long and not interesting ` ; var someText = ` Something ${desc.toUpperCase()} long and not interesting ` ; someText function upper(str) { return str.toUpperCase(); } var someText = ` Something ${upper(desc)} long and not interesting ` ; someText desc = "sucky"; someText var someGlobal = 'some global'; function getGlobal() { return someGlobal; } var someText = ` Something ${getGlobal()} long and not interesting ` ; someText someGlobal = 'still a global' getGlobal() someText function foo(str) { var name = 'foo'; console.log(str) } function bar() { var name = 'bar'; foo(`Hello from ${name}`); } var name = 'initial'; bar() var someText = `Some text has: ${upper(`${desc}`)}`; // ------------------------- // Tagged String Literal // ------------------------- function foo(strings, ...values) { console.log( strings ); console.log( values ); } var desc = "awesome"; foo`Everything is ${desc}!`; foo `Everything is ${desc}!`; foo `Everything is ${desc}!`; foo`Everything is ${desc} and ${desc2}!`; foo(`Everything is ${desc} and ${desc2}!`); // function? foo`${desc} and ${desc2}`; String.raw`Hello` String.raw`Hello` === "Hello" String.raw`Hello\n\n${desc}` String.raw` Hello\n\n${desc}` // ------------------------- // Arrow Functions // ------------------------- var neg = x => -x neg(234) [1, 3, 5] a = [2, 4, 6, 8, 10] a.filter( e => e % 2) a = a.map( v => v * 2 ); a = a.map( v => { return v * 2 }); // [8, 16, 24, 32, 40]