0

I'm digging into EMCA6 and I would like to know if this:

var fruits= [10,20,30];
this.iterator = 1; 
var result = fruits.map(function(nrb) {
       return nbr + this.iterator;
}.bind(this));

is equivalent to :

var fruits= [10,20,30];
this.iterator = 1;
var result = fruits.map( nbr => nbr + this.iterator);

For me this is exactly the same thing but I was wondering if I was missing something. Any trap ?

François Richard
  • 6,817
  • 10
  • 43
  • 78
  • Yes it is for your purposes. But you really should not use `this` in a global scope - I hope that was only for this example. – Bergi Sep 19 '15 at 13:58
  • lets say I'm in the global scope, what is the difference of scope between fruits and iterator then ? – François Richard Sep 19 '15 at 14:01
  • One is a property, the other is a variable. Just use two variables - and give them some local scope if possible. – Bergi Sep 19 '15 at 14:02

0 Answers0