ecmascript-harmony

unexpected strict mode reserved word — yield? Node v0.11, harmony, es6

烂漫一生 提交于 2019-12-04 08:17:49
问题 Trying to use a new ES6 based node.js ODM for Mongo (Robe http://hiddentao.github.io/robe/) Getting "unexpected strict mode reserved word" error. Am I dong something wrong here? test0.js "use strict"; // Random ES6 (works) { let a = 'I am declared inside an anonymous block'; } var Robe = require('robe'); // :( var db1 = yield Robe.connect('127.0.0.1'); Run it: C:\TestWS>node --version v0.11.10 C:\TestWS>node --harmony test0.js C:\TestWS\test0.js:12 var db1 = yield Robe.connect('127.0.0.1'); ^

Why I can not start harmony mode by “node --harmony test.js” from command line?

妖精的绣舞 提交于 2019-12-04 06:32:18
问题 The problem is: longhao33@hePC:~$ node --harmony test.js /home/longhao33/test.js:1 (function (exports, require, module, __filename, __dirname) { let str = 'es666666666666'; ^^^ SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:413:25) at Object.Module._extensions..js (module.js:452:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at

Garbage-collected cache via Javascript WeakMaps

折月煮酒 提交于 2019-12-04 01:46:01
I want to cache large objects in JS. These objects are retrieved by key, and it makes sense to cache them. But they won't fit in memory all at once, so I want them to be garbage collected if needed - the GC obviously knows better. It is pretty trivial to make such a cache using WeakReference or WeakValueDictionary found in other languages, but in ES6 we have WeakMap instead, where keys are weak. So, is it possible to make something like a WeakReference or make garbage-collected caches from WeakMap ? is it possible to make WeakReference from WeakMap or make garbage-collected cache from WeakMap

ES6 global import

≡放荡痞女 提交于 2019-12-04 00:28:16
问题 What is the best way to import some modules in all of the files of the project, so I don't have to write stuff like: import React from 'react'; import Reflux from 'reflux'; import reactMixin from 'react-mixin'; in almost every single file? 回答1: The other answer covers this, but not with valid ES6, so I'm adding my own. Make a central file to import your react components, in some central react.js file export {default as React} from 'react'; export {default as Reflux} from 'reflux'; export

Ecmascript 6 support on Node.js

情到浓时终转凉″ 提交于 2019-12-03 17:53:00
问题 I've been working with KoaJS for a while, and we can easily use the 'let' keyword and the generators when using the --harmony flag but I couldn't find how much support for does the node v0.11.x provides while using the same. I tried using the default value argument initialization but couldn't succeed. Is there any source available which can list the no of features of ECS 6 supported in node v0.11.x using the harmony flag? Or if there is any npm module available for node that might allow me to

Co.js and bluebird.js — what's the difference?

坚强是说给别人听的谎言 提交于 2019-12-03 15:01:50
Could someone help me understand the differences between using Koa.js and Bluebird.js with ES6 Harmony. Specifically, how does co( function * () { //stuff } ); compare to, Promise.coroutine( function * () { //stuff } ); It just seems Koa should be using Bluebird and not recreating the wheel. What's different? For now the difference is that Koa allows yielding more than just promises. However a feature is being added that allows not only yielding callbacks, thunks etc but any arbitrary thing that comes to your mind. Bluebird is also the fastest. So after this version koa should be just using

How can I feature-detect ES6 generators?

我与影子孤独终老i 提交于 2019-12-03 10:59:11
I'm really enjoying ES6 generators. Is there a way I can detect generator support in browsers? I know generators might not be in a lot of browsers (or possible no browsers at all) at the moment, but that's OK for my purposes. I tried: try { function *(){} } catch(err) { console.log("No generators"); } But it doesn't seem to work. How can I detect support for ES6 generators in browsers? Jeremy J Starcher One of the few times that eval is actually the right solution. For language construct changes, you need something like this: try { eval("(function *(){})"); } catch(err) { console.log(err);

How to enable harmony syntax support in coffeescript?

强颜欢笑 提交于 2019-12-03 07:56:45
I used node.js(0.11.13) with --harmony flag and used function *() and yield keywords. I tried to simplify my development on node.js with help of coffeescript, so far it works great but I went into troubles with yield and declaring a generator - it complains about 'reserved keyword yield' . Any ideas? Another way to open the gate to the black dimension is: co = require 'co' sleep = require 'co-sleep' co(`function*(){1` console.log 'hi!' `yield sleep(1000)` console.log 'bye!' `1}`)() It's seems to be perfectly valid coffee-script, though, webstorm cofeescript plugin cries about errors, but it

What's the purpose of an asterisk (*) in ES6 generator functions

我是研究僧i 提交于 2019-12-03 05:25:54
问题 Can someone explain to me: why are generator functions in ES6 marked by asterisk symbol? For example, instead of: function *someGenerator() { yield 1; yield 2; yield 3; } we could write: function someGenerator() { yield 1; yield 2; yield 3; } or even: var someGenerator = () => { yield 1; yield 2; yield 3; } var someObject = { someGenerator() { yield 1; yield 2; yield 3; } } The JS compiler can detect that someGenerator contains yield operator at the parse time and make a generator from this

How to make an iterator out of an ES6 class

余生长醉 提交于 2019-12-03 02:57:04
问题 How would I make an iterator out of an ES6 class in the same manner as JS1.7 SomeClass.prototype.__iterator__ = function() {...} syntax? [EDIT 16:00] The following works: class SomeClass { constructor() { } *[Symbol.iterator]() { yield '1'; yield '2'; } //*generator() { //} } an_instance = new SomeClass(); for (let v of an_instance) { console.log(v); } WebStorm flags *[Symbol.iterator]() with a 'function name expected' warning directly following the asterix, but otherwise this compiles and