learning-javascript
  • Introduction
  • JavaScript ES5 教學
    • 工具準備
    • 流程控制
    • JavaScript 基本特性, 變數
    • Function及Callback function
    • Array及JSON的操作
    • Object, Scope, this
    • ES5中的自訂物件類型-prototype
    • 進階-再講prototype
    • JavaScript重點整理
    • Closure
    • 多個JS檔, module, timer
    • 進階-module pattern
    • 其他
  • 實際應用
    • Server - HTTP request & response
    • Client - 用Fetch跟Server要資料
  • JavaScript ES6 教學
    • 箭頭函數Arrow Function
Powered by GitBook
On this page
  • ES6 如何在class上模擬private data/method:
  • ES6裡的Prototype
  • let , const 為 block level 變數的關鍵字
  • shorthand syntax of Method definitions
  • 其餘部份待補充, 可先參考

JavaScript ES6 教學

PreviousClient - 用Fetch跟Server要資料Next箭頭函數Arrow Function

Last updated 7 years ago

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

ES6 如何在class上模擬private data/method:

上述兩個link都提到兩種方式WeakMap & Symbol.

ES6裡的Prototype

class 本質上是prototype的syntactical sugar)的導入. []

Since ECMAScript 6, the [[Prototype]] is accessed using the accessors Object.getPrototypeOf() and Object.setPrototypeOf().

let , const 為 block level 變數的關鍵字

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

shorthand syntax of Method definitions

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:

http://www.2ality.com/2016/01/private-data-classes.html
http://stackoverflow.com/questions/27849064/how-to-implement-private-method-in-es6-class-with-traceur
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain
https://github.com/lukehoban/es6features
arrows
classes
enhanced object literals
template strings
destructuring
default + rest + spread
let + const
iterators + for..of
generators
unicode
modules
module loaders
map + set + weakmap + weakset
proxies
symbols
subclassable built-ins
promises
math + number + string + array + object APIs
binary and octal literals
reflect api
tail calls