Tag: ecmascript 6

如何在es6类中声明私有variables和私有方法

在es5中,我们使用构造函数 function Person(name,gender){ var initial =""; // we use var key word to make variable private function getNameWithInitial(){ // this is the private method to get name with initial console.log(this); initial = this.gender ==="male"?"Mr. ":"Mrs. "; return initial + this.name; } this.name = name; this.gender = gender; this.getName = function(){ return getNameWithInitial.call(this); } } var […]

ES6中的导入/导出工作如何?

我正在学习ES6标准,所以我从一个非常基本的示例代码开始。 我的第一个文件是Rectangle.js class Rectangle { perimeter(x, y) { return (2 * (x + y)); } area(x, y) { return (x * y); } } export default class { Rectangle }; 而在另一个文件solve-1.js ,我有一些像这样的导入 import Rectangle from './Rectangle'; function solveRect(l, b) { if (l < 0 || b < 0) { console.log(`Rectangle dimensions should be greater than […]

快速处理程序中的es6和弦箭头function

有没有一个理由不使用箭头,而是expressjs中的正则函数expression式处理中间件? app.use(mountSomething()) router.use(mountSomethingElse()) app.get('/', (req,res,next)=> { next(); }) route.get('/path', (req,res,next)=>{ res.send('send') })

Visual Studio 2015 – Javascript ES6不能正常工作

我正在玩VS 2015 JavaScript / NodeJS IDE,我打算使用ES6作为JavaScript的语言风格,但是我注意到Visual Studio不认识ES6(即使我在各种网站上看到VS应该能识别ES6 )。 有没有人知道如何使VS 2015发挥不错(语法高亮,智能感知等)与ES6? 我也修改了文件的扩展名为.JSX和.ES6,以防VS帮助。 没有运气…

在严格模式下的节点0.12.x const问题

我正在运行节点v0.12.7,并通过npm安装量angular器。 现在我试图用这个简单的教程来运行conf.js,并且在执行命令protractor conf.js时出现以下错误: [launcher] Process exited with error code 1 C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\index.js:25 const builder = require('./builder'); ^^^^^ SyntaxError: Use of const in strict mode. at exports.runInThisContext (vm.js:73:16) at Module._compile (module.js:443:25) at Object.Module._extensions..js (module.js:478:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Module.require (module.js:365:17) at require (module.js:384:17) at Object.<anonymous> (C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\built\protractor.js:3:17) at Module._compile (module.js:460:26) at Object.Module._extensions..js (module.js:478:10) 不能更新节点,因为它会产生依赖关系问题(我正在使用节点0.12.17的已经build好的项目上工作)。 在量angular器上使用–harmony标志不起作用。 […]

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 我的命令行启动与所有和谐选项的应用程序: […]

为什么不从`.map`callback中产生回报?

学习生成器 – 4»捕获错误! 该解决scheme使用for loop但我只是找不到任何MDN – 迭代协议 ,指的是callback内的产量。 我会猜测答案就是don't do that但是如果有人有时间或倾向提供一个解释,请提前致谢! 码: function *upper (items) { items.map(function (item) { try { yield item.toUpperCase() } catch (e) { yield 'null' } } } var badItems = ['a', 'B', 1, 'c'] for (var item of upper(badItems)) { console.log(item) } // want to log: A, B, null, C […]

SyntaxError:意外的令牌导入

当我正在运行index.js它给错误SyntaxError: Unexpected token import 。 虽然我使用babel将ES6转换为ES5。 的package.json { "name": "espract", "version": "1.0.0", "description": "", "main": "app.js", "scripts": { "build": "babel src -d lib" }, "author": "", "license": "ISC", "devDependencies": { "babel-cli": "^6.3.17" } } Person.js 'use strict'; module.exports = class Person { constructor(firstname, lastname) { this.firstName = firstname; this.lastName = lastname; } greet() { console.log(`Hello, […]

SailsJS支持ES6吗?

有没有办法在sails.js中获得ES6 ?

vscodedebuggingES6应用程序

我有VSCode 0.5.0。 我将compilerOptions标志设置为“ES6”,编辑器开始认识到我的ES6代码是正确的。 我已经安装了babel。 我的摩卡testing使用babel编译器,我的testing通过。 当我用babel-node启动它时,我的应用程序从命令行运行,没有任何问题。 当我从VSCode中debugging应用程序时,它将在没有ES6支持的情况下启动,并且应用程序因ES6语法问题而失败。 有没有debugging设置,我错过了打开?