“Deklaracja funkcji JavaScript vs funkcja strzałki” Kod odpowiedzi

Funkcja normalna vs strzałka w JavaScript

// Normal Function
let add = function (num1, num2) {
return num1 + num2;
}

// Arrow Function
let add = (num1, num2) => num1 + num2;
madhav

Deklaracja funkcji JavaScript vs funkcja strzałki

Regular functions created through function declarations / expressions are both constructible and callable. ... Arrow functions (and methods) are only callable i.e arrow functions can never be used as constructor functions. Hence, they can never be invoked with the new keyword.
Fragile Frog

Funkcja strzałki vs funkcja w JavaScript

// Arrow function vs function
// Function in JavaScript
function regular(){
  console.log("regular function");
}
regular(); //regular function

// Arrow Function
const arrow = () => console.log("Arrow function");
arrow(); //Arrow function
Chetan Nada

funkcja strzałki JS vs

// currently common pattern
var that = this;
getData(function(data) {
  that.data = data;
});

// better alternative with arrow functions
getData(data => {
  this.data = data;
});
RedConcrete

Odpowiedzi podobne do “Deklaracja funkcji JavaScript vs funkcja strzałki”

Pytania podobne do “Deklaracja funkcji JavaScript vs funkcja strzałki”

Więcej pokrewnych odpowiedzi na “Deklaracja funkcji JavaScript vs funkcja strzałki” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu