ecmascript-harmony

Restarting a Generator in Javascript

自闭症网瘾萝莉.ら 提交于 2020-01-03 19:57:08
问题 In node (0.11.9, with the --harmony flag), how do I restart a generator after it finishes? I tried doing generator.send(true); but it says the send() method doesn't exists. 回答1: A bit late, but this is just a FYI. At the moment, the send method is not implemented in Node, but is in Nightly (FF) - and only in some way. Nightly: If you declare your generator without the *, you'll get an iterator that has a send method: var g = function() { var val = yield 1; // this is the way to get what you

How to add --harmony node flag to grunt-express

我的梦境 提交于 2020-01-02 04:50:34
问题 I'm using grunt-express to do local development. here is my GruntFile.js var path = require('path'); module.exports = function(grunt){ grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), uglify:{ options:{ banner:'/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n' } }, express:{ server:{ options:{ debug:true, server: path.resolve('app.js') } } }, env : { options:{ }, dev : { NODE_ENV : 'development' }, prod : { NODE_ENV : 'production' } }, mochaTest:{ test:{ options:

`this` in global scope in ECMAScript 6

倖福魔咒の 提交于 2020-01-02 04:28:10
问题 I've tried looking in the ES6 draft myself, but I'm not sure where to look: Can someone tell me if this in ES6 necessarily refers to the global object? Also, will this object have same members as the global scope? If you could answer for ES5 that would be helpful as well. I know this in global scope refers to the global object in the browser and in most other ES environments, like Node. I just want to know if that's the defined behavior by the spec or if that's extended behavior that

Access [[NativeBrand]] / [[Class]] in ES6 (ECMAScript 6)

元气小坏坏 提交于 2020-01-02 02:56:06
问题 I was reading over the draft for ES6, and I noticed this note in the Object.prototype.toString section: Historically, this function was occasionally used to access the string value of the [[Class]] internal property that was used in previous editions of this specification as a nominal type tag for various built-in objects. This definition of toString preserves the ability to use it as a reliable test for those specific kinds of built-in objects but it does not provide a reliable type testing

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

梦想与她 提交于 2020-01-01 05:16:31
问题 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? 回答1: 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

Promise chaining: Use result from previous promise in next then callback [duplicate]

ぃ、小莉子 提交于 2019-12-30 10:38:12
问题 This question already has answers here : How do I access previous promise results in a .then() chain? (17 answers) Closed 4 years ago . I'm using straight ES6 Promises (with the es6-promise polyfill library) and I'm running into a problem with accessing results from previous promises in chained ones. This problem is identical in the context of Angular/Q, but I'm dissatisfied with the answer and wanted to see if there's a better way: How to access result from the previous promise in AngularJS

Immediate function using JavaScript ES6 arrow functions

非 Y 不嫁゛ 提交于 2019-12-28 03:45:11
问题 Does anyone know how to write an immediate function using ES6 arrow syntax? Here's the ES3/5 way of doing it: (function () { //... }()); I've tried the following but get an unexpected token error on the last line. (() => { //... }()); You can test this here: http://www.es6fiddle.net/hsb8bgu4/ 回答1: From the Arrow functions examples, (() => "foobar")() // returns "foobar" So, the function invocation operator should be outside. (() => { //... })(); Sample: http://www.es6fiddle.net/hsb8s1sj/ 回答2:

Is it impossible to tell if a function is a generator function if .bind() has been called on it?

二次信任 提交于 2019-12-23 11:00:19
问题 Looks like calling .bind(this) on any generator function breaks my ability to see if the function is a generator. Any ideas on how to fix this? var isGenerator = function(fn) { if(!fn) { return false; } var isGenerator = false; // Faster method first // Calling .bind(this) causes fn.constructor.name to be 'Function' if(fn.constructor.name === 'GeneratorFunction') { isGenerator = true; } // Slower method second // Calling .bind(this) causes this test to fail else if(/^function\s*\*/.test(fn

Is it possible to use Harmony (ES6) with JSXTransformer.js?

旧时模样 提交于 2019-12-23 07:52:56
问题 I've had great luck using React's JSXTransformer.js to develop using JSX in the browser: <script src="http://fb.me/JSXTransformer-0.11.1.js"></script> <script type="text/jsx"> /** @jsx React.DOM */ ... </script> To reduce boilerplate, I'd like to use some of the features from Harmony, e.g. arrow functions. Facebook's JSX Compiler Service has a harmony checkbox which transforms ES6 to more traditional JS: var f = v => this.props[v]; // becomes var f = function(v) { return this.props[v]; }.bind

TypeError: redeclaration of let error in Firebug console if running ES6 code

纵然是瞬间 提交于 2019-12-22 04:08:25
问题 I am learning ES6, so bear me please. Following is the code which is running fine, if I click the Run button one time, but on second hit it starts showing TypeError: redeclaration of let myArr error. Let me know about this weird (may be not) behavior. let myArr = [34,45,67,2,67,1,5,90]; let evenArr = []; let oddArr = []; myArr.forEach(x => { if (x % 2 === 0) { evenArr.push(x); } else { oddArr.push(x); } }); console.log(evenArr); console.log(oddArr); Error - 回答1: ES6 does not allow you to do