Last active
August 29, 2015 14:21
-
-
Save piyasde/30ea5ba509100d41ab67 to your computer and use it in GitHub Desktop.
es6 Fat Arrow Functions in Browser (Currently supported in Firefox)
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="UTF-8"> | |
| </head> | |
| <body> | |
| <div id ="resultLen"></div> | |
| <div id ="resultSearch"></div> | |
| </body> | |
| <script> | |
| var a = ["Hydrogen","Helium","Lithium","Beryllium"]; | |
| var a3 = ((s) => s.length); | |
| var theValue = a3(a); | |
| console.log(theValue); | |
| document.getElementById('resultLen').innerHTML = theValue; | |
| var str = "Please find where there is a find"; | |
| var searchStr = "find"; | |
| var es6pos = (totalStr,stringToSearch) => str.indexOf(stringToSearch); | |
| theValue = es6pos(str,searchStr); | |
| console.log(theValue); | |
| document.getElementById('resultSearch').innerHTML = theValue; | |
| var arr = ["a", "b", "c"]; | |
| arr.forEach(elem => console.log(elem)); | |
| function Person(){ | |
| this.age = 14; | |
| this.grow = () => { | |
| return this.age++; // |this| properly refers to the person object | |
| }; | |
| } | |
| var p = new Person(); | |
| console.log("es6 --"+ p.grow()); | |
| console.log("es6 --"+ p.grow()); | |
| </script> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment