1 Basic usage
ES6 allows you to define functions using the arrows (=>).
var f = v => v;
The above arrow function is equivalent to:
var f = function (V) {return
V;
};
If the arrow function requires no arguments or requires more than one argument, a
For this problem in the ES6 arrow function, the es6 arrow function this
Brief Introduction: this in Arrow functions points to different functions defined by general functions. this in Arrow functions is defined by this when defining functions,
The arrow function is one of the most recent updates to ECMAScript 6. It introduces a new syntax for defining functions with an "arrow" (=>), which ... It's a fortress. The main difference between an arrow function and a traditional JavaScript
The original is from my Front-end blog:
http://www.hacke2.cn/arrow-functions-and-their-scope/
http://es6rocks.com/2014/10/arrow-functions-and-their-scope/the original link translation: @liningone Rock ES6 China Station is about to go online, we
This article brings the content is about the JS in the arrow function format &this and the common function of the difference between the explanation, there is a certain reference value, the need for friends can refer to, I hope to help you.
The
Point of this in es5
var factory = function(){ this.a = ‘a‘; this.b = ‘b‘; this.c = { a:‘a+‘, b:function(){return this.a} } };console.log(new factory().c.b()); // a+
Through es5 syntax call, the returned result is a +, and
ES6 allows you to define functions using the arrow (= =)var f = a = > a// equals varfunction(a) { return A; }If the arrow function does not require arguments or requires more than one argument, a parenthesis is used to represent the parameter
The ES6 standard adds a new function: arrow function.Why is it called Arrow Function? Because it's defined by an arrow:x = x * xThe above arrow functions are equivalent to:function (x) { return x * x;}The arrow function is equivalent to an
The difference between JS arrow function and ordinary function 1. Bubondin thisEach newly defined function has its own this value before the arrow function appearsvar myObject = {value:1, getvalue:function ( {console.log (this.value)},
This article abstract: http://www.liaoxuefeng.com/The ES6 standard adds a new function:arrow function.Why is it called Arrow Function? Because it's defined by an arrow:x => x * xThe above arrow functions are equivalent to:function (x) { return x *
xTable of Contents [1] pain point [2] settlement [3] Basic usage [4] callback function [5] precautions beforeThe This mechanism is related to function calls, while scopes are related to function definitions. Is there anything that can be linked to
A new function is added to the ES6 standard: arrow function (arrowhead).
x => x *x
the arrow above is equivalent to:
function (x) {return
x*x;
}
The arrow function acts as an anonymous function and simplifies the definition of the
The interview was asked the difference between the arrow function and the normal function ...
-_-||
Borrow a chestnut from someone else:
function make () {
return () =>{
console.log (this);
}
}
var TestFunc = Make.call ({name: ' foo '});
Today we are going to introduce the arrow functions in ES6. Grammar
Let's look at the syntax of the arrow function first:
([param] [, param]) => {
statements
}
param =>
Param is a parameter, depending on the number of parameters, divided into
Arrow functionsMaking short single-line functions easier to write and readA normal function can be a function declaration or function expression, but an arrow function is always an expressionNormal function (converts the name to uppercase)const
A deep understanding of this in the Javascript arrow function and a deep understanding of javascript
First, let's take a look at the code. This is a Countdown class "Countdown" and Its instantiation process:
function Countdown(seconds) {
Scope of the Arrow function
The arrow function scope is bound to the context of the parent.Test Cases:
var obj = {
id:1, show
: () => {
console.log (this.id)
}
}
obj.show ()
Output: undefinedIn this case the show function is
This article is purely their own combination of online article summary, have questions and different ideas welcome message/******************** Simple Small Example ********************/var test =function () {Console.log (this);};Test (); Window/****
ES6 the introduction of the arrow function has three advantages, first, a concise syntax, and the second, implicit return, can be written as a line, and thirdly, when you perform a click operation, the statement is not inside a function.Visit Es6.io
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.