Arrow Function

Bashar Ayyash
1 min readSep 9, 2015

--

This post part of Starter to ES6

Is special way to handle functions with short callbacks

normal function:
function story(post, date){ return post + date;}

arrow function:
(post, date) => post + date;

Also, arrow function doesn’t shadow inner this (lexical this) so you don’t need to add another reference to this so you can use inside handler like below:

var posting = {
article: “Arrow Function”,
savePost: function(message, handler){ handler(message);
},
postArticle: function(){
var that = this;
this.savePost(“Article “, function(message){ that.article;//get article console.log(message + that.article); }); }
}

posting.postArticle();

Using ES6 arrow function:
var posting = {
article: “Arrow Function”,
savePost: function(message, handler){ handler(message);
},
postArticle: function(){ this.savePost(“Article “, message => console.log(message + this.article)); }
}

posting.postArticle();

This post part of Starter to ES6

--

--

Bashar Ayyash

Front End Developer, I’m confident that Vue.js is as powerful as React, but way more flexible and a lot easier to learn