Tag: ecmascript 6

esprima-six npm模块发生了什么事?

我的npm项目有esprima-six npm模块作为传递依赖。 最近,已经不可能下载了,如下面的npm install输出所示: npm ERR! 404 Not Found npm ERR! 404 npm ERR! 404 'esprima-six' is not in the npm registry. npm ERR! 404 You should bug the author to publish it npm ERR! 404 It was specified as a dependency of 'syntax-error' npm ERR! 404 npm ERR! 404 Note that you can also […]

意想不到的严格模式保留字 – 屈服? 节点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 […]

节点5.10传播运营商不工作

根据文档 ,最新的节点(Node 5+)应该默认支持spread运算符,如下所示: const newObj = { …oldObj, newProperty: 1 } 并且我已经安装了节点5.10.1(例如,'node -v'告诉我这是什么)。 但是我仍然得到这个错误: c:\[myprojectfolder]>node index.js c:\[myprojectfolder]\index.js:21 …oldObj, ^^^ SyntaxError: Unexpected token … at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:387:25) at Object.Module._extensions..js (module.js:422:10) at Module.load (module.js:357:32) at Function.Module._load (module.js:314:12) at Function.Module.runMain (module.js:447:10) at startup (node.js:146:18) at node.js:404:3 我错过了什么?

ES6模板Literals V串联的string

我有以下Ecma-Script-6 template literals let person = {name: 'John Smith'}; let tpl = `My name is ${person.name}.`; let MyVar="My name is "+ person.name+"."; console.log("template literal= "+tpl); console.log("my variable = "+MyVar); 输出如下: template literal= My name is John Smith. my variable = My name is John Smith. 这是小提琴。 我试图寻找确切的差异,但无法find它,我的问题是这两个声明有什么区别, let tpl = `My name is ${person.name}.`; 和 […]

使用babel时意外的保留字'import'

在我的NodeJSv4.1.1代码中使用Babel。 得到了要求挂钩在: require("babel-core/register"); $appRoot = __dirname; module.exports = require("./lib/controllers/app"); 在随后的lodaded .js文件中,我正在做: import { Strategy as LocalStrategy } from "passport-local"; 但是,这在CLI中产生以下错误: import { Strategy as LocalStrategy } from "passport-local"; ^^^^^^ SyntaxError: Unexpected reserved word at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:413:25) at loader (/Users/*/Documents/Web/*/node_modules/babel-core/node_modules/babel-register/lib/node.js:128:5) at Object.require.extensions.(anonymous function) [as .js] (/Users/*/Documents/Web/*/node_modules/babel-core/node_modules/babel-register/lib/node.js:138:7) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at […]

常量vs让调用require时

由于io.js现在支持ES6,你终于可以使用const和let关键字了。 显然, let成为var的inheritance者,只是有一些超级大国。 但是const呢? 当然,我知道“常量”意味着什么,但是我想知道什么时候使用它(关于最佳实践)。 例如,如果我创build一个需要另一个模块的模块,我可以写: 'use strict'; const util = require('util'); const foo = function () { // Do something with util }; module.exports = foo; 基本上我已经用const代替var每一个var 。 一般来说,我认为这是可以的,但是如果遵循这个模式,它使我更多地使用const不是let ,因为大多数variables不是字面意义上的“variables”。 这是不错的风格? 我应该去let ? 什么时候应该selectconst来let ?

TypeError:无法匹配'undefined'或'null'

码 client.createPet(pet, (err, {name, breed, age}) => { if (err) { return t.error(err, 'no error') } t.equal(pet, {name, breed, age}, 'should be equivalent') }) 错误 client.createPet(pet, (err, {name, breed, age}) => { ^ TypeError: Cannot match against 'undefined' or 'null'. 为什么我得到这个错误? 我对ES6的了解让我推测,只有当数组或对象被解构或其子 undefined或为null才会出现此错误。 我不知道函数参数是用来匹配的。 如果他们是那么为什么如果我试图解构他们其中之一只是一个错误? (这不是undefined或null )。

如何在node.js中禁用WebStorm分号检查

如何禁用node.js中的WebStorm分号检查? 我已经尝试了下面的方法,但他们不工作: 检查选项use semicolon to terminate statement 将JavaScript版本更改为ecma6 有任何想法吗?

在ES6中使用分号

我印象中分号已经被ES6淘汰了。 不过,我今天碰到这个: 不起作用: let i = 0 [0, 1, 2, 3, 4, 5, 6].forEach(item => console.log(item)) 作品: let i = 0; [0, 1, 2, 3, 4, 5, 6].forEach(item => console.log(item)) 为什么在这里需要分号,我应该什么时候使用它们?

节点v6在对象传播上失败

我有一个问题,为什么节点v6.7将无法运行此代码: var a = { foo: 'bar' } var b = { …a, my: 'sharona' } console.log(b) 任何人都有一个想法,为什么会这样? 我认为v6支持对象传播..? 但是我猜不是? 这是我看到的错误: /home/teselagen/ve/tnrtest.js:6 …a, ^^^ SyntaxError: Unexpected token … at Object.exports.runInThisContext (vm.js:76:16) at Module._compile (module.js:528:28) at Object.Module._extensions..js (module.js:565:10) at Module.load (module.js:473:32) at tryModuleLoad (module.js:432:12) at Function.Module._load (module.js:424:3) at Module.runMain (module.js:590:10) at run (bootstrap_node.js:394:7) at startup (bootstrap_node.js:149:9) […]