From f53940c5c0f05899547127cb43b44c43962f266c Mon Sep 17 00:00:00 2001 From: Chris Reyes Date: Mon, 15 Oct 2018 19:59:50 -0700 Subject: [PATCH] add advantages for arrow examples (#18911) explained benefits with code examples --- .../javascript/es6/arrow-functions/index.md | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/client/src/guide/english/javascript/es6/arrow-functions/index.md b/client/src/guide/english/javascript/es6/arrow-functions/index.md index ee3129eff8..0132ee6f95 100644 --- a/client/src/guide/english/javascript/es6/arrow-functions/index.md +++ b/client/src/guide/english/javascript/es6/arrow-functions/index.md @@ -45,20 +45,31 @@ let newOneWithOneParam = a => { } ``` -An incredible advantage of the arrows function is that you can not rebind an arrow function. It will always be called with the context in which it was defined. Just use a normal function. +### advantages of arrow sytnax +1. It will always be called with the context in which it was defined. Therefore there is no existence of the this keyword. + ```javascript -// Old Syntax -axios.get(url).then(function(response) { - this.data = response.data; -}).bind(this); - -// New Syntax -axios.get(url).then(response => { - this.data = response.data; -}); - + // Old Syntax + axios.get(url).then(function(response) { + this.data = response.data; + }).bind(this); + + // New Syntax + axios.get(url).then(response => { + this.data = response.data; + }); + ``` + * before arrow functions each function had it's own this contect +2. shorter more readable functions +```javascript + // Old Syntax + const sumValues = function (a, b) { + return a+b; + } + + // New Syntax + const sumValues = (a,b) => a+b; ``` + * since it's a one line return we can ommit the brackets - -I don’t think I need to give an explanation for this. It's straightforward.