Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save piyasde/30ea5ba509100d41ab67 to your computer and use it in GitHub Desktop.
Save piyasde/30ea5ba509100d41ab67 to your computer and use it in GitHub Desktop.
es6 Fat Arrow Functions in Browser (Currently supported in Firefox)
<!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","Beryl­lium"];
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