ecmascript-harmony

JavaScript double colon (bind operator)

穿精又带淫゛_ 提交于 2019-12-17 02:28:28
问题 As you know, there is a proposal for a shortcut for .bind() function, so you can write: ::this.handleStuff and it will work like that in es5: this.handleStuff.bind(this) My question is: will it be possible to pass arguments this way? I mean a way of writing this with the aforementioned shortcut: this.handleStuff.bind(this, 'stuff') It's a pretty common pattern in React, so it would be nice to shorten it a little. 回答1: No. The bind operator (spec proposal) comes in two flavours: Method

What's the difference between ES6 Map and WeakMap?

六月ゝ 毕业季﹏ 提交于 2019-12-13 02:43:40
问题 Looking this and this MDN pages it seems like the only difference between Maps and WeakMaps is a missing "size" property for WeakMaps. But is this true? What's the difference between them? 回答1: From the very same page, section "Why Weak Map?": The experienced JavaScript programmer will notice that this API could be implemented in JavaScript with two arrays (one for keys, one for values) shared by the 4 API methods. Such an implementation would have two main inconveniences. The first one is an

What is the motivation for bringing Symbols to ES6?

家住魔仙堡 提交于 2019-12-11 17:41:05
问题 UPDATE : Recently a brilliant article from Mozilla came up. Read it if you're curious. As you may know they are planning to include new Symbol primitive type in ECMAScript 6 (not to mention some other crazy stuff). I always thought that the :symbol notion in Ruby is needless; we could easily use plain strings instead, like we do in JavaScript. And now they decide to complicate things in JS with that. I don't understand the motivation. Could someone explain to me whether we really need symbols

Difference between simple import statement and System.import in ES6 Module Loader

吃可爱长大的小学妹 提交于 2019-12-11 02:41:45
问题 Is anybody able to explain the difference between a simple import and a System.import statement of the ES6 Module Loader (or Polyfills like System.js, Webpack etc.) Something like System.import('https://code.jquery.com/jquery.js').then(); seems to be possible, as well as a simple import 'jquery'; Is System.import the only possibility to have a callback after the import statement? 回答1: You can use the System.import inside <script> tags where import aren't supported, and you can also load

How to tell eslint to allow staged ECMA-Script dynamic imports

一笑奈何 提交于 2019-12-10 13:29:48
问题 I want to use the now "Stage-3" proposal import() . If I lint my code with ESLint it's complaining about: Parsing error: 'import' and 'export' may only appear at the top level Which is correct for the static form of import but not for the new, dynamic one. I don't find the right option to make ESLint allow that. Can someone give me a hint? 回答1: Of course is Gyandeep right. It's no question of rules but of the parser (That's what parsing error means after all…). So I use now babel-eslint with

Restructuring TypeScript internal modules to external modules

蓝咒 提交于 2019-12-10 10:23:29
问题 I have a website that uses a large typescript code base. All clases as in their own files, and wrapped with an internal module like so: file BaseClass.ts module my.module { export class BaseClass { } } file ChildClass.ts module my.module { export ChildClass extends my.module.BaseClass { } } All file are included globally with script tags, in the appropriate order (using ASP.NET Bundling). I would like to move to a more modern setup and use webpack. I would like my module syntax to use

How to use five digit long Unicode characters in JavaScript

回眸只為那壹抹淺笑 提交于 2019-12-10 01:48:20
问题 In JavaScript I can do this: foo = "\u2669" // 1/4 note But I can't do this foo = "\u1D15D" // full note -five hex digits It will be interpreted as "\u1D15" followed by "D" Are there any workarounds for this? UPDATE 2012-07-09: The proposal for ECMAScript Harmony now includes support for all Unicode characters. 回答1: In the MDN documentation for fromCharCode, they note that javascript will only naturally handle characters up to 0xFFFF. However, they also have an implementation of a fixed

ES7 Getting result from an array of promises using await generator

早过忘川 提交于 2019-12-10 00:40:36
问题 Given an array of promises, what's the idiomatic way to get the results in ES7? Here's what I want to do: async function getImports() { let imports = [System.import('./package1.js'), System.import('./package2.js')]; let promises = await* imports; let results = []; await promises.forEach(val => val.then(data => results.push(data))); //seems hacky console.log(results); // array of 2 resolved imports } The result is correct, but I'm still doing a forEach and a then to turn the resolved promises

ES6 yield : what happens to the arguments of the first call next()?

强颜欢笑 提交于 2019-12-08 12:45:07
问题 Consider this snippet of code : function foo(a) { console.log("Mul =", a); return a * 2; }; function * process(start) { // next() #1 var result = start; console.log("Pre-processing =", result); result = yield foo(result); // next() #2 console.log("Process result 1 =", result); result = yield foo(result); // next() #3 console.log("Process result 2 =", result); result = yield foo(result); // next() #4 console.log("Process result 3 =", result); return foo(result); } var it = process(1); console

ES6 classes, member properties definitions as static/shared

一曲冷凌霜 提交于 2019-12-08 09:18:30
问题 I am testing classes in ES 6 with io.js 2.xx the example below I took from Mozilla, Things are getting on tracks (OOp in JS), at least we now have direct inheritance (at syntax level) with the 'extends' directive... the problem I pose is that member properties are defined inside constructor this is at least a syntax problem... (been searched through the web and found very few information about this) will be more a of a problem when ESxx try to had visibility directives to property members (in