Arrow Functions vs. Fat Arrow Functions

I found on the Internet about all the names, the functions of the arrows and the functions of the arrows of the fat , but there is no information about what is different between them.

Are there any differences?

+4
source share
4 answers

Such a question needs a little explanation ...

ECMAScript 5

There were no arrow functions in the ES5 specification . Then it was customary to use traditional function expressions, for example:

// Example n°1
var myFunction = function () {
  return 'Hello!';
};

// Example n°2
var obj = {
  myFunction: function () {
    return 'Hello!';
  }
};

// Example n°3
var arr = ['foo', 'bar'];
arr.map(function (item) {
  return 'Hello, ' + item + '!';
};

CoffeeScript

CoffeeScript , , (->) (=>).

, CoffeeScript ES5 (). CoffeeScript :

# Example n°1
myFunction = -> 'Hello!'

# Example n°2
obj =
  myFunction: -> 'Hello!'

# Example n°3
arr = ['foo', 'bar']
arr.map((item) -> "Hello, #{item}!")

, - , CoffeeScript, ES5. , , . CoffeeScript jQuery. , :

// Here "this" is "window"
console.log(this);

$(document).ready(function () {
  // Here "this" is "document"
  console.log(this);
});

"this" , ES5:

var that = this;

$(document).ready(function () {
  console.log(that);
});

CoffeeScript :

// "this" is "window"!
$(document).ready => console.log this

, :

// "this" is "document"
$(document).ready -> console.log this

ECMAScript 6 (2015)

ES2015 . CoffeeScript. ES6 , , CoffeeScript. ES6 :

// Here "this" is "window"
$(document).ready(() => console.log(this));

, , ES5:

$(document).ready(function () {
  // Here "this" is "document"
  console.log(this);
});
+10

?

.

, " " .

CoffeeScript, - .

+4

CoffeeScript , .

0

Tag wiki: ( )

CoffeeScript JavaScript EcmaScript6, - , . CoffeeScript "- > ", "= > " , JavaScript , " " .

, JS, .

-1

Source: https://habr.com/ru/post/1675522/


All Articles