ES6 (ECMAScript 6) is the upcoming new version of the JavaScript language standard, code-named Harmony (meaning of harmony, obviously did not keep pace with our country, we have entered the Chinese Dream version). The last standard was enacted in 2009 ES5. The ES6 is currently in the process of standardization and is expected to release the officially finalized v
Object-oriented programming:two basic concepts of objects in Java:1. Class: Class is the template of the object, for example leader this is general term leader, not specifically who.2: Instance: an instance is an object created from a class, and many instances can be created according to class leader: Liyi,yingjiangyon
ES6 Babel is correctly installed in JavaScript, es6babel
This document describes how to install Babel6.x ~ First, you can use Babel online conversion https://babeljs.io/repl/
Then go to the topic: Install Babel (command line environment, for Babel6.x)
1. First install babel-cli (used to use babel on the terminal)
Npm install-g babel-cli
2. then install the babel-preset-es2015 plug-in
Npm install -- save ba
1, ES6 provides a more approach to the traditional language, introduced the concept of Class (Class) as an object template. classyou can define a class by keyword.2.// Defining Classes class Point { constructor (x, y) { this. x = x; this. y = y; } ToString () {
Here is the recursive/trailing recursive implementation of the reverse sequence (array/string) made with JavaScript. In addition, the early adopters used a ES6 destructuring assignment + spread operator to make a more functional version (only supported arrays).Correctness can pass the test (see the demo on my Github and write a small test frame), but efficiency is mark-especially with the
1 Object.getPrototypeOf . The method can be used to get the parent class from the subclass. Therefore, you can use this method to determine whether a class inherits another class.2, super this keyword, can be used as a function, can also be used as an object. In both cases, its usage is completely different.The first case, super as a function call, represents the
We can execute generators from generators, and delegate the iteration control with the yield* keyword.Yo Dawg, I heard you like generators, so I put generators inside your generators. function* create3to4counter () { 3; return 4;} function* createcounter () { 1; 2; = yield* create3to4counter (); Console.log ("Four", four) 5;} for (Let I of Createcounter ()) { console.log (i)}/*12345* / [Javascript] Delegate
( = ) 以及默认值 return name;}Default and deconstructed arrays// = [] 防止调用无参函数报错 Cannot read property ‘Symbol(Symbol.iterator)‘ of undefined function createGrid([width = 5, height = 5] = []) { //=[], createGrid()可以直接使用 return `Generating a grid of ${width} by ${height}`;}Default and Deconstruction objectsfunction can make an object a default parameter and use an object to deconstructBecause the array is location-based, an advantage of the object's default value is to skip the parameter for pro
)
Babel Es6.js-w--out-file Es5.jsBabel Es6.js--watch--out-file es5.js
4. Compile the entire SRC folder and output it to the Lib folder (use-D or--out-dir)
Babel src-d LibBabel Src--out-dir Lib
5, compile the entire SRC folder and output to a file
Babel src--out-file es5.js
6, direct Input Babel-node command, you can run the ES6 code directly in the command
Es6 JavaScript Object Method Object.assign ()December 01, 2016 16:42:34Hits: 385831 Basic usageThe Object.assign method is used for merging objects, copying all enumerable properties of the source object (sources) to the destination object (target).[JavaScript]View PlainCopy
var target = {a:1};
var source1 = {B:2};
var source2 = {C:3};
Objec
object instantiated by a parent class): class person{ Constructor (name,age) { this. Name = name; this. Age = Age ; } Say () { console.log ("I am the say function of the parent class");} } Class Student extends person{ Constructor (name,age,sex) { super (nam
() is that in the traditional method, the parameter is first converted to a numeric type (with number ()) and then judged, and the two methods are only valid for the value, All non-numeric types return FALSE. This can be seen from the above example.(3) Number.parseint (), Number.parsefloat ()ES6 the Global Method parseint () and parsefloat () to the number object, the behavior is completely intact:// true // trueThe benefit of this is a gradual subst
, isextensible.14.SymbolsSymbol is a basic type. The symbol is generated by calling the symbol function, which receives an optional name parameter, and the symbol returned by the function is unique.var key = Symbol ("key"); var key2 = Symbol ("key"= = Key2 //false15.PromisesPromises is an object that handles asynchronous operations and uses a Promise object to organize the code in a chained way, making the code more intuitive (like jquery's deferred object).functionfakeajax (URL) {return NewPro
(size)]
In the code above, the size attribute of object x is a Symbol value, soObject.keys(x) ,Object.getOwnPropertyNames(x)It cannot be obtained. This results in the effect of a non-private internal method. If you are not clear about ES6 definitions, you can skip this section or check your own documents. I will also share the following articles, in general, the new JavaScript standards are becoming more an
execution results. Unlike the generator function, when a generator function executes, it executes with its caller in the same thread, each execution order is determined, ordered, and the order of execution does not change. Unlike threads, the generator function can suspend execution at the internal yield flag point.
By introducing the pause, execution, and recovery execution of the generator function, we know what the generator function is, and now we're throwing a question: what's the use of
.PromisesPromises is an object that handles asynchronous operations and uses a Promise object to organize the code in a chained way, making the code more intuitive (like jquery's deferred object).functionfakeajax (URL) {return NewPromise (function(Resolve, reject) {//settimeouts is for effect, typically we would handle XHR if(!URL) { returnSetTimeout (Reject, 1000); } returnSetTimeout (Resolve, 1000); });}//no URL, Promise rejectedFakeajax (). Then (function() {Console.log (' Success
the symbol function, which receives an optional name parameter, and the symbol returned by the function is unique.var key = Symbol ("key"); var key2 = Symbol ("key"= = Key2 //false15.PromisesPromises is an object that handles asynchronous operations and uses a Promise object to organize the code in a chained way, making the code more intuitive (like jquery's deferred object).functionfakeajax (URL) {return NewPromise (function(Resolve, reject) {//settimeouts is for effect, typically we would ha
The introduction of a new string literal-template string in ES6, in addition to using inverted quotation marks ('), means that they do not appear to be any different from ordinary strings. In the simplest case, they are ordinary strings:
Context.filltext (' Ceci n ' est pas une cha?ne. ', x, y);
Context.filltext (' Ceci n ' est pas une cha?ne. ', x, y);
It is called a template string because the template string is a simple string inter
parameter.
There are two kinds of situations:
Assuming that the incoming parameter does not have a .then method, the returned Promise object becomes a resolve state, and its resolve value is the object itself.
Assuming that the incoming parameter comes with a then method (called an thenable object), the type of the object becomes promise and its then method becomes a Promise.prototype.then method.
Promise is the solution to the asynchronous solution?
Finally, it is important to say that th
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.