Tag: ecmascript harmony

SyntaxError:意外标识符(ES6中的生成器)

在阅读MDN生成器的文档后,我想出了这个简单的实验: var nodes = { type: 'root', value: [ { type: 'char', value: 'a' }, { type: 'char', value: 'b' }, { type: 'char', value: 'c' }, ], }; function* recursiveGenerator(node) { if (node.type === 'root') { node.value.forEach(function (subnode) { for (var suffix of recursiveGenerator(subnode)) { yield suffix; } }); } else { yield node.value; […]

如何用和谐旗启动全局npm模块

我写了一个可以安装在全局dm-npm的npm模块。 我喜欢在该模块中使用co。 我怎样才能告诉模块,它启动全球时,与和谐标志运行? 这里是package.json: { "name": "dm-npm", "version": "0.0.3", "description": "npm helper", "main": "index.js", "scripts": { "test": "mocha –reporter nyan", "start": "node –harmony ./bin/dm-npm" }, "repository": { "type": "git", "url": "https://github.com/divramod/dm-npm.git" }, "keywords": [ "npm", "template" ], "author": "", "license": "ISC", "bugs": { "url": "https://github.com/divramod/dm-npm/issues" }, "homepage": "https://github.com/divramod/dm-npm", "devDependencies": { "chai": "^2.1.0", "mocha": "^2.1.0" }, […]

获取节点和nvm的ES6function

我已经有节点0.10。*和我安装nvm,然后通过nvm我再次安装0.11.13和0.10。 节点 – 版本返回0.11.13 我尝试使用一些我阅读过的ES6function,但没有尝试过。 我用node –harmony index.js运行我的脚本 …args说SyntaxError: Unexpected token . let x = 5; 也给出一个错误 – SyntaxError: Unexpected identifier 我在哪里可以find目前支持0.11.13?

在Ubuntu下,箭头函数不能在节点–harmony中工作

我试图在Ubuntu 14.04下使用node v0.10.33箭头函数(我正在使用–harmony标志运行节点),但是我得到这个错误: console.log( [1,2,3,4].map(x => x*x) ); ^ SyntaxError: Unexpected token > at Module._compile (module.js:439:25) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:906:3

对Node.js的Ecmascript 6支持

我一直在使用KoaJS一段时间,当使用–harmony标志时,我们可以很容易地使用'let'关键字和生成器,但是我找不到节点v0.11.x提供了多less支持同时使用相同的。 我尝试使用默认值参数初始化,但不能成功。 是否有任何可用的源代码可以列出节点v0.11.x中使用和声标志支持的ECS 6的function? 或者如果有任何npm模块可用于节点,可能允许我使用相同的? 提前致谢。

node.js / ES6 /类创build:SyntaxError:意外的保留字

我尝试在我的node.js / express应用程序上创build一个类。 它在基本的JS /原型模式下工作,例如: function MyClass() { /* constructor code */ }; MyClass.prototype.myMethod = function() { /* method code */ }; module.exports = MyClass; 但我想要使用类,构造函数,扩展…关键字。 我试过了: class MyClass { constructor() { /* constructor code */ } myMethod() { /* method code */ } } 但它不起作用,错误是: class MyClass { ^^^^^ SyntaxError: Unexpected reserved word 我的命令行启动与所有和谐选项的应用程序: […]

NodeJS和谐在导入时给出了SyntaxError

我正在使用标志child_process –harmony标记ES6testing节点,但是在导入时第一步失败。 有任何想法吗? import {'spawn'} from child_process; console.log(spawn); 而我运行: node –harmony test.js 我得到: :1 (function (exports, require, module, __filename, __dirname) { import {spawn} f ^^^^^^ SyntaxError: Unexpected token import

在JavaScript中实现monad

现在, node.js支持ECMAScript Harmony生成器,我们可以在Haskell中简洁地写出monadic代码: function monad(unit, bind) { return function (f) { return function () { var g = f.apply(this, arguments); return typeOf(g) === "Generator" ? send() : unit(g); function send(value) { var result = g.next(value); if (result.done) return unit(result.value); else return bind(result.value, send); } }; }; } function typeOf(value) { return Object.prototype.toString.call(value).slice(8, -1); } 在上面的代码中, […]

在nodejs中启用Harmony代理

是否有可能在nodejs中启用EcmaScript 6 Harmony Proxies? 如果是的话,有什么优点和缺点? 有没有关于如何使用它们的文档? 谢谢 !

意想不到的严格模式保留字 – 屈服? 节点v0.11,和谐,es6

尝试为Mongo使用基于ES6的新Node.js ODM(Robe http://hiddentao.github.io/robe/ ) 获取“意外的严格模式保留字”错误。 我在这里弄错了什么? 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'); 运行: 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'); ^^^^^ SyntaxError: Unexpected strict mode reserved […]