[
  {
    "path": ".gitignore",
    "content": "node_modules\npackage.json"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2017 Alex Bardanov\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "_template.md",
    "content": "> ES6:\n\n```js\n\n```\n\n> Javascript\n\n```js\n\n```"
  },
  {
    "path": "ecma6/arrayComprehension.md",
    "content": "# Array Comprehension\n\nThe array comprehension syntax is a JavaScript expression which allows you to quickly assemble a new array based on an existing one. Comprehensions exist in many programming languages and the upcoming *ECMAScript 7* standard defines array comprehensions for JavaScript.\n\n> ES7:\n\n```js\n[for (num of [ 1, 4, 9 ]) Math.sqrt(num)];\n```\n\n> Javascript\n\n```js\n[ 1, 4, 9 ].map(function(a){ return Math.sqrt(a) });\n```\n\n> ES7:\n\n```js\n[for (x of [ 1, 2, 3]) for (y of [ 3, 2, 1 ]) x*y]\n```\n\n> Javascript\n\n```js\nvar a = [ 1, 2, 3],\n    b = [ 3, 2, 1 ],\n    result = [];\n\nfor (var i = 0; i < a.length; i ++)\n    for (var j = 0; j < b.length; j ++)\n        result.push(a[i] * b[j]);\n```"
  },
  {
    "path": "ecma6/arrows.md",
    "content": "# Arrows\n\nArrows are a function shorthand using the => syntax. They are syntactically similar to the related feature in C#, Java 8 and CoffeeScript. They support both expression and statement bodies. Unlike functions, arrows share the same lexical this as their surrounding code.\n\n## Expression bodies\n\n> ES6:\n\n```js\nvar odds = evens.map(v => v + 1);\n\nvar nums = evens.map((v, i) => v + i);\n```\n\n> Javascript\n\n```js\nvar odds = evens.map(function (v) {\n  return v + 1;\n});\n\nvar nums = evens.map(function (v, i) {\n  return v + i;\n});\n```\n\n## Statement bodies\n\n> ES6:\n\n```js\nnums.forEach(v => {\n    fives.push(v);\n});\n```\n\n> Javascript\n\n```js\nnums.forEach(function (v) {\n  fives.push(v);\n});\n```\n\n## Lexical `this`\n> ES6:\n\n```js\nvar bob = {\n  _name: \"Bob\",\n  _friends: [],\n  printFriends() {\n    this._friends.forEach(f =>\n      console.log(this._name + \" knows \" + f));\n  }\n}\n```\n\n> Javascript\n\n```js\nvar bob = {\n  _name: \"Bob\",\n  _friends: [],\n  printFriends: function() {\n    var _this = this;\n    this._friends.forEach(function (f) {\n      return console.log(_this._name + \" knows \" + f);\n    });\n  }\n};\n```"
  },
  {
    "path": "ecma6/classes.md",
    "content": "# Classes\n\nES6 classes are a simple sugar over the prototype-based OO pattern. Having a single convenient declarative form makes class patterns easier to use, and encourages interoperability. Classes support prototype-based inheritance, super calls, instance and static methods and constructors.\n\n> ES6:\n\n```js\nclass SkinnedMesh{\n  update(camera) { }\n  static defaultMatrix() {\n    return new THREE.Matrix4();\n  }\n}\n```\n\n> Javascript\n\n```js\nfunction SkinnedMesh() {}\n\nSkinnedMesh.prototype.update = function update(camera) { };\n\nSkinnedMesh.defaultMatrix = function defaultMatrix() {\n  return new THREE.Matrix4();\n};\n```\n\n## Constructor\n\n> ES6:\n\n```js\nclass SkinnedMesh {\n  constructor(geometry, materials) {\n    this.idMatrix = SkinnedMesh.defaultMatrix();\n    this.bones = [];\n    this.boneMatrices = [];\n  }\n  update(camera) {\n\n  }\n  static defaultMatrix() {\n    return new THREE.Matrix4();\n  }\n}\n```\n\n> Javascript\n\n```js\nfunction SkinnedMesh(geometry, materials) {\n  this.idMatrix = SkinnedMesh.defaultMatrix();\n  this.bones = [];\n  this.boneMatrices = [];\n}\n\nSkinnedMesh.prototype.update = function update(camera) {\n  Function.prototype.update.call(this);\n};\n\nSkinnedMesh.defaultMatrix = function defaultMatrix() {\n  return new THREE.Matrix4();\n};\n```\n\n## Extends\n\n> ES6:\n\n```js\nclass SkinnedMesh extends THREE.Mesh {\n  update(camera) {\n    super.update();\n  }\n}\n```\n\n> Javascript\n\n```js\nvar _inherits = function (subClass, superClass) {\n  if (typeof superClass !== \"function\" && superClass !== null) {\n    throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass);\n  }\n  subClass.prototype = Object.create(superClass && superClass.prototype, {\n    constructor: {\n      value: subClass,\n      enumerable: false,\n      writable: true,\n      configurable: true\n    }\n  });\n  if (superClass) subClass.__proto__ = superClass;\n};\n\nfunction SkinnedMesh() {\n  if (_THREEMesh != null) {\n    _THREEMesh.apply(this, arguments);\n  }\n}\n\n_inherits(SkinnedMesh, _THREEMesh);\n\nSkinnedMesh.prototype.update = function update(camera) {\n  THREEMesh.prototype.update.call(this);\n};\n```"
  },
  {
    "path": "ecma6/default.md",
    "content": "# Default, Rest, Spread\n\nCallee-evaluated default parameter values. Turn an array into consecutive arguments in a function call. Bind trailing parameters to an array. Rest replaces the need for arguments and addresses common cases more directly.\n\n## Default\n> ES6:\n\n```js\nfunction f(x, y=12) {\n  return x + y;\n}\n```\n\n> Javascript\n\n```js\nfunction f(x) {\n  var y = arguments[1] === undefined ? 12 : arguments[1];\n  return x + y;\n}\n```\n\n## Rest\n> ES6:\n\n```js\nfunction f(x, ...y) {\n  return x * y.length;\n}\n```\n\n> Javascript\n\n```js\nfunction f(x) {\n  var y = Array.prototype.slice.call(arguments, 1);\n\n  return x * y.length;\n}\n```\n\n## Spread\nPass each elem of array as argument\n> ES6:\n\n```js\nconsole.log(...[1,2,3]);\n```\n\n> Javascript\n\n```js\nconsole.log.apply(console, [1, 2, 3]);\n```\n"
  },
  {
    "path": "ecma6/destructuring.md",
    "content": "# Destructuring\n\nDestructuring allows binding using pattern matching, with support for matching arrays and objects. Destructuring is fail-soft, similar to standard object lookup foo[\"bar\"], producing undefined values when not found.\n\n## List matching\n> ES6:\n\n```js\nvar [a, , b] = [1,2,3];\n```\n\n> Javascript\n\n```js\nvar ref = [1, 2, 3];\n\nvar a = ref[0];\nvar b = ref[2];\n```\n\n## Object matching\n> ES6:\n\n```js\nvar { first: a, second: { something: b }, third: c } = getSomething();\n```\n\n> Javascript\n\n```js\nvar _getSomething = getSomething();\n\nvar a = _getSomething.first;\nvar b = _getSomething.second.something;\nvar c = _getSomething.third;\n```\n\n## Object matching shorthand\n> ES6:\n\n```js\nvar { first, second, third } = getSomething();\n```\n\n> Javascript\n\n```js\nvar _getSomething = getSomething();\n\nvar first = _getSomething.first;\nvar second = _getSomething.second;\nvar third = _getSomething.third;\n```\n\n## Parameter destructuring\n> ES6:\n\n```js\nfunction g({name: x}) {\n  console.log(x);\n}\ng({name: 5});\n```\n\n> Javascript\n\n```js\nfunction g(_ref) {\n  var x = _ref.name;\n  console.log(x);\n}\ng({ name: 5 });\n```\n\n## Fail-soft destructuring\n> ES6:\n\n```js\nvar [a] = [];\n```\na === undefined;\n\n## Fail-soft destructuring with defaults\n> ES6:\n\n```js\nvar [a = 1] = [];\n```\na === 1;\n"
  },
  {
    "path": "ecma6/generators.md",
    "content": "# Generators\n\nGenerators simplify iterator-authoring using function* and yield. A function declared as function* returns a Generator instance. Generators are subtypes of iterators which include additional next and throw. These enable values to flow back into the generator, so yield is an expression form which returns a value (or throws).\n\n> ES6:\n\n```js\nfunction* idMaker(){\n    var index = 0;\n    while(true)\n        yield index++;\n}\n\nvar gen = idMaker();\n\nconsole.log(gen.next().value); // 0\nconsole.log(gen.next().value); // 1\nconsole.log(gen.next().value); // 2\n```\n\n>Javascript\n\n```js\nfunction idMaker(){\n    var value = 0;\n    \n    return {\n        next: function(){\n            return {\n                value: ++value\n            };\n        }\n    }\n}\n\nvar gen = idMaker();\n\nconsole.log(gen.next().value); // 0\nconsole.log(gen.next().value); // 1\nconsole.log(gen.next().value); // 2\n```\n\n> ES6:\n\n```js\nfunction* anotherGenerator(i) {\n  yield i + 1;\n  yield i + 2;\n  yield i + 3;\n}\nfunction* generator(i){\n  yield i;\n  yield* anotherGenerator(i);\n  yield i + 10;\n}\n\nvar gen = generator(10);\n\nconsole.log(gen.next().value); // 10\nconsole.log(gen.next().value); // 11\nconsole.log(gen.next().value); // 12\nconsole.log(gen.next().value); // 13\nconsole.log(gen.next().value); // 20\n```"
  },
  {
    "path": "ecma6/iterators.md",
    "content": "# Iterators, For..Of\nIterator objects enable custom iteration like CLR IEnumerable or Java Iterable. Generalize for..in to custom iterator-based iteration with for..of. Don’t require realizing an array, enabling lazy design patterns like LINQ.\n\n> ES6\n\n```js\nlet fibonacci = {\n  [Symbol.iterator]() {\n    let pre = 0, cur = 1;\n    return {\n      next() {\n        [pre, cur] = [cur, pre + cur];\n        return { done: false, value: cur }\n      }\n    }\n  }\n}\n\nfor (var n of fibonacci) {\n  if (n > 1000)\n    break;\n  console.log(n);\n}\n```"
  },
  {
    "path": "ecma6/let.md",
    "content": "# Let, Const\n\nBlock-scoped binding constructs. let is the new var. const is single-assignment. Static restrictions prevent use before assignment.\n\n\n> ES6:\n\n```js\nfunction f() {\n  {\n    let x;\n    {\n      // okay, block scoped name\n      const x = \"sneaky\";\n      // error, const\n      x = \"foo\";\n    }\n    // error, already declared in block\n    let x = \"inner\";\n  }\n}\n```\n\n> ES6:\n\n```js\nvar pixel = () => {\n    {\n      var x = 1,\n          y = 1;\n      let color = 'red';\n    }\n    console.log(x, y, color); // 1, 1, undefined.\n}\n```"
  },
  {
    "path": "ecma6/modules.md",
    "content": "# Modules\n\nLanguage-level support for modules for component definition. Codifies patterns from popular JavaScript module loaders (AMD, CommonJS). Runtime behaviour defined by a host-defined default loader. Implicitly async model – no code executes until requested modules are available and processed.\n\n## Export module\n> ES6\n\n```js\nexport function sum(x, y) {\n  return x + y;\n}\nexport var pi = 3.141593;\n```\n\n> Javascript\n\n```js\nexports.sum = sum;\nfunction sum(x, y) {\n  return x + y;\n}\nvar pi = exports.pi = 3.141593;\n```\n\n## Import module\n> ES6:\n\n```js\nimport * as math from \"lib/math\";\n```\n\n> Javascript\n\n```js\nvar math = require(\"lib/math\");\n```\n\n## Export default\n> ES6:\n\n```js\nexport default function(x) {\n    return Math.exp(x);\n}\n```\n\n> Javascript\n\n```js\nmodule.exports = function (x) {\n  return Math.exp(x);\n};\n```"
  },
  {
    "path": "ecma6/objectLiterals.md",
    "content": "# Enhanced Object Literals\n\nObject literals are extended to support setting the prototype at construction, shorthand for foo: foo assignments, defining methods and making super calls. Together, these also bring object literals and class declarations closer together, and let object-based design benefit from some of the same conveniences.\n\n## Shorthands\n> ES6:\n\n```js\nvar obj = {\n    handler\n};\n```\n\n> Javascript\n\n```js\nvar obj = {\n  handler: handler\n};\n```\n\n## Methods\n> ES6:\n\n```js\nvar obj = {\n  toString() {\n    return \"null\";\n  }\n};\n```\n\n> Javascript\n\n```js\nvar obj = {\n  toString: function toString() {\n    return \"null\";\n  }\n};\n```\n\n## Computed (dynamic) property names\n> ES6:\n\n```js\nvar obj = {\n  [ 'prop_' + (() => 42)() ]: 42\n};\n```\n\n> Javascript\n\n```js\nvar obj = {};\n\nobj[\"prop_\" + (function () {\n  return 42;\n})()] = 42;\n```"
  },
  {
    "path": "ecma6/templateStrings.md",
    "content": "# Template Strings\n\nTemplate strings provide syntactic sugar for constructing strings. This is similar to string interpolation features in Perl, Python and more. Optionally, a tag can be added to allow the string construction to be customized, avoiding injection attacks or constructing higher level data structures from string contents.\n\n## Multiline strings\n\n> ES6:\n\n```js\n`In JavaScript this is\n not legal.`\n```\n\n> Javascript\n\n```js\n\"In JavaScript this is\\n not legal.\";\n```\n\n## Templating\n\n> ES6:\n\n```js\nvar name = \"Bob\", time = \"today\";\nvar query = `Hello ${name}, how are you ${time}?`\n```\n\n> Javascript\n\n```js\nvar name = \"Bob\",\n    time = \"today\";\nvar query = \"Hello \" + name + \", how are you \" + time + \"?\";\n```"
  },
  {
    "path": "examples/arrows+promises.js",
    "content": "return db.getUser(id)\n  .then(user => user.invites)\n  .then(invites => {\n    invites.forEach(invite => invite.accept());\n  });\n"
  },
  {
    "path": "readme.md",
    "content": "# ECMAScript 6 Features\n\n### [Arrows](https://github.com/dnbard/es6-guide/blob/master/ecma6/arrows.md)\nArrows are a function shorthand using the => syntax. They are syntactically similar to the related feature in C#, Java 8 and CoffeeScript. They support both expression and statement bodies. Unlike functions, arrows share the same lexical this as their surrounding code.\n\n### [Classes](https://github.com/dnbard/es6-guide/blob/master/ecma6/classes.md)\nES6 classes are a simple sugar over the prototype-based OO pattern. Having a single convenient declarative form makes class patterns easier to use, and encourages interoperability. Classes support prototype-based inheritance, super calls, instance and static methods and constructors.\n\n### [Enhanced Object Literals](https://github.com/dnbard/es6-guide/blob/master/ecma6/objectLiterals.md)\nObject literals are extended to support setting the prototype at construction, shorthand for foo: foo assignments, defining methods and making super calls. Together, these also bring object literals and class declarations closer together, and let object-based design benefit from some of the same conveniences.\n\n### [Template Strings](https://github.com/dnbard/es6-guide/blob/master/ecma6/templateStrings.md)\nTemplate strings provide syntactic sugar for constructing strings. This is similar to string interpolation features in Perl, Python and more. Optionally, a tag can be added to allow the string construction to be customized, avoiding injection attacks or constructing higher level data structures from string contents.\n\n### [Destructuring](https://github.com/dnbard/es6-guide/blob/master/ecma6/destructuring.md)\nDestructuring allows binding using pattern matching, with support for matching arrays and objects. Destructuring is fail-soft, similar to standard object lookup foo[\"bar\"], producing undefined values when not found.\n\n### [Default, Rest, Spread](https://github.com/dnbard/es6-guide/blob/master/ecma6/default.md)\nCallee-evaluated default parameter values. Turn an array into consecutive arguments in a function call. Bind trailing parameters to an array. Rest replaces the need for arguments and addresses common cases more directly.\n\n### [Let, Const](https://github.com/dnbard/es6-guide/blob/master/ecma6/let.md)\nBlock-scoped binding constructs. let is the new var. const is single-assignment. Static restrictions prevent use before assignment.\n\n### [Iterators, For..Of](https://github.com/dnbard/es6-guide/blob/master/ecma6/iterators.md)\nIterator objects enable custom iteration like CLR IEnumerable or Java Iterable. Generalize for..in to custom iterator-based iteration with for..of. Don’t require realizing an array, enabling lazy design patterns like LINQ.\n\n### [Generators](https://github.com/dnbard/es6-guide/blob/master/ecma6/generators.md)\nGenerators simplify iterator-authoring using function* and yield. A function declared as function* returns a Generator instance. Generators are subtypes of iterators which include additional next and throw. These enable values to flow back into the generator, so yield is an expression form which returns a value (or throws).\n\n### [Modules](https://github.com/dnbard/es6-guide/blob/master/ecma6/modules.md)\nLanguage-level support for modules for component definition. Codifies patterns from popular JavaScript module loaders (AMD, CommonJS). Runtime behaviour defined by a host-defined default loader. Implicitly async model – no code executes until requested modules are available and processed.\n\n# ECMAScript 7 Features\n\n### [Array Comprehension](https://github.com/dnbard/es6-guide/blob/master/ecma6/arrayComprehension.md)\nThe array comprehension syntax is a JavaScript expression which allows you to quickly assemble a new array based on an existing one."
  }
]