JavaScript ES6 教學
ES6 = ECMAScript 6 = ECMAScript 2015.
ES6 還是未有直接support class的 private member.
當使用const/let等時, 且在node.js上, 則一定要運行在Strict Mode Code下, 即
use strict
. 不然會出現 Block-scoped declarations (let, const, function, class) not yet supported outside strict mode上述兩個link都提到兩種方式WeakMap & Symbol.
class
本質上是prototype的syntactical sugar)的導入. [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain]Since ECMAScript 6, the [[Prototype]] is accessed using the accessors Object.getPrototypeOf() and Object.setPrototypeOf().
if(true){
var x = 1;
}
console.log(x); //1
if(true){
let y = 2; //its lifetime is only in thie scope
}
console.log(y); //exception, undefined
Given the following code:
var obj = {
foo: function() {},
bar: function() {}
};
You are now able to shorten this to:
var obj = {
foo() {},
bar() {}
};
上面網站裡的功能清單 ES6 includes the following new features:
Last modified 5yr ago