Tag: ecmascript 6

Visual Studio 2015编辑器使用ECMA Script 6语法显示错误

我正在使用Node.js Web服务器编写应用程序。 我使用了自从ECMA Script 2015以来可用的箭头函数 ,并且正确地构build了我的项目。 不过,Visual Studio 2015在“错误列表”窗口中显示了很多错误: 这真的很烦人,有谁知道如何解决这个VS2015的行为?

禁用eslint分析错误消息

在我的代码中我有一个条件导出: if (process.env.NODE_ENV === 'testing') export myFunc; 在es6中,这个声明是不允许的,因为导入和导出应该是最高级别的,但是在一些插件和webpack中使用babel这个条件在构build时被淘汰,所以在我的结果代码中这个导出是顶层的或者是不存在的。 但eslint报告parsing错误,我想摆脱它。 /*eslint-disable */不起作用,因为,这不是一个规则违规,这是一个parsing错误。 有没有可能的解决方法? PS:我知道我可以commonjs它,但我想坚持es6。

如何在package.json中指定所需的和声参数?

我将在cli Node.js应用程序中使用解构赋值 ,因此我需要使用–harmony_destructuring参数运行node 。 有什么办法可以在package.json bin部分指定所需的和声参数吗?

用Javascript导入和导出

根据这个问题如何在另一个JavaScript文件中包含JavaScript文件? 。 似乎很多人都有兴趣将大的JavaScript项目分解成小模块,并导出/导入模块以重用代码。 经过一番研究,导入/导出是为这个function而devise的。 根据参考资料,它们最初是在ES6中定义的。 更新 随附此function的主要浏览器的最新版本。 要获得最新状态,请始终参阅参考文献。 (如果你使用nodejs,Modules( https://nodejs.org/dist/latest-v5.x/docs/api/modules.html )是最好的方法) Refrerences : https://developer.mozilla.org/en/docs/web/javascript/reference/statements/import https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export

如何在节点项目中使用babel编译的类?

这是一个非常简单的课程,我正在testing在es2015中编写的: "use strict"; class Car { constructor(color) { this.color = color; } } export default Car; 我用babel-cli来传输那个类,所以它可以在节点中使用…这是输出: "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Car = function Car(color) { _classCallCheck(this, Car); this.color = […]

ES6模块:为什么先前导出的模块不被“子”模块所知?

我正在尝试为我的Meteor / Node应用程序构build一个基于模块的体系结构。 我有一个client/main.js导入一个imports/module1/index.js 。 imports/module1/index.js在导入组件imports/module1/component/component1.js后,导入一个imports/module1/component/component1.js imports/module1/api/api.js 总结起来,简化的树就像这样 .client/main.js |_imports/module1/index.js |_imports/module1/api/api.js |_imports/module1/component/component1.js api.js文件如下所示: export default { myFunction1 (arg1, arg2) { // function stuff }, myFunction2 (arg1, arg2) { // function stuff }, } 我希望能够在imports/module1/component/component1.js调用myFunction1(ar1,arg2) ,但不起作用。 我错过了什么?

使用module.exports和ES6导出导入

我试图将一个函数导入到一个文件,然后从该文件中导出。 这应该是直接的,但由于某种原因,我不能得到它的工作。 search_action.js function search_actions() { this.receive_results = function() { return { type: 'RECEIVE_RESULTS', results: results } } } module.exports = search_actions index.js require('es6-promise').polyfill(); var SearchActions = require('./search_actions.js') var search_actions = new SearchActions() //console.log(search_actions.receive_results) export search_actions.receive_results 尽pipeconsole.log(search_actions.receive_results)打印了该函数,但index.js底部的导出仍会失败并出现意外令牌。 那么这样做的正确方法是什么?

我还需要使用NodeJs5的babel吗?

据我所知节点5支持ES2015,但是当我尝试运行类似的东西 import sizeOf from 'image-size'; 我明白了 $> node -v v5.9.0 $> node test.js /Users/dev/tmp/test.js:1 (function (exports, require, module, __filename, __dirname) { import sizeOf from 'image-size'; ^^^^^^ SyntaxError: Unexpected token import … 现在,当我search谷歌时,我发现使用babel的build议(使用ES2015预设的.babelrc),但是如果node5支持ES2015,为什么我需要babel?

为了循环内的const用法,为什么这个行为?

我在我的nodejs代码中有一个for循环 const saveDocument = co.wrap(function *(documentData, user, locale) { var now = moment(); var creationDateLongString = now.format("YYYYMMDDHHmmss"); var creationDateShortString = now.format("YYYYMMDD"); var outputChildFolder = documentData.code + '_' + creationDateLongString + '_' + documentCounter; var outputFolder = config.files.incomingDocumentsDir + '/' + outputChildFolder; ++documentCounter; yield fs.mkdir(outputFolder) var xmlFileName = documentData.code + "-" + creationDateLongString + ".xml"; var […]

ES2015模块在使用Babel.js的Node.js中不起作用?

我想用babel.js编译器在Node.js中使用ES2015模块,但是它不起作用。 这是我有什么: 的package.json { "name": "test", "version": "0.0.1", "private": true, "scripts": { }, "devDependencies": { "babel-core": "^6.9.0", "babel-plugin-transform-runtime": "^6.9.0", "babel-preset-es2015": "^6.9.0", "babel-preset-node5": "^11.1.0", } } .babelrc { "presets": ["es2015"], "plugins": [ "transform-runtime" ] } 服务器/ index.js require('babel-core').transform('code', { presets: ['node5'], }); import { test } from './file1'; console.log(test); 服务器/ file1.js export const test = 'its […]