Tag: ecmascript 6

ES6类中的constr.apply(this,args)

我已经使用下面的函数来创build一些未知类的实例: Kernel.prototype._construct = function (constr, args) { function F() { constr.apply(this, args); // EXCEPTION! } F.prototype = constr.prototype; return new F(); }; 如果我使用原型,一切正常: function Person(name, surname) { this.name = name; this.surname = surname; } var person = Kernel._construct(Person, ["name", "surname"]); // WORKS! 但是,有些人正在使用节点v4 +中使用ES6本机类的库: class Person { constructor(name, surname) { this.name = name; this.surname = […]

ECMAScript 6类属性下划线前缀

我所见过的类模式很像这样: class Foo { constructor(x, y, z) { this._x = x; this._y = y; this._z = z; } get x() { return this._x; } set x(value) { //I acctually do some stuff here this._x = value; } get y() { return this._y; } set y(value) { //I acctually do some stuff here this._y = value; […]

在React中没有使用ES6获取来定义获取方法

嘿家伙我有我的第一个反应js应用程序中获取函数的麻烦。 这是我的项目的结构: hello-world — app — components — main.jsx — node_modules — public — build.js — index.html — package.json 这是我用npm安装的: npm install react react-dom babel-core babel-loader babel-preset-es2015 babel-preset-react webpack –save-dev npm install –save isomorphic-fetch es6-promise 我使用webpack webpack.config module.exports = { entry: './app/components/main.jsx', output: { path: './public/', filename: "build.js", }, module: { loaders: [ { exclude: […]

如何使用ES6模块导入导入path

有没有什么好的方法来使用dynamicpath优雅地加载一个模块(IDE可以提示或进入文件)或从根目录开始导入模块? import * as Q from 'q'; import * as loopback from 'loopback'; import datasources from '../../../datasources.json'; import app from '../../../server'; import {ApiError, ValidationError, DatabaseError} from'../../../utils/error-handlers';

用Webstorm(Babel)进行ES6debugging

有Webstorm V10,巴贝尔文件观察员工作正常,一切都很好。 现在我想debugging的代码,任何方式来debuggingES6文件本身或必须做的JS输出文件babel编译? 请指教。

为什么我的迭代器再次进入?

我有以下程序 – 我使用genny.js来处理asynchronousstream量控制 – 我已经尝试与suspend.js相同 – 类似的错误。 我正在使用Stripe nodejs API。 我的迭代函数似乎被调用两次 – 这是造成一个错误 – 我不明白为什么被调用两次。 这一定是一个简单的思维把戏,我没有看到。 var genny = require('genny') genny.longStackSupport = true var stripe = require("stripe")("sk_live_….") fetchCharges = genny.fn(function* (d) { console.log("Before fetchCharges") var charges = yield fetchList(d()) console.log("After fetchCharges – found ", charges.length) return true }) fetchList = genny.fn(function* (done) { console.log("before fetchList") […]

无法在节点v6.4.0中启用尾部呼叫优化

我不想在节点/ es2015中进行尾部调用优化,但是我一直得到RangeError: Maximum call stack size exceeded 。 所以我尝试了一个非常简单的testing函数: function countTo(n, acc) { if(n === 0) { return acc; } return countTo(n – 1, acc + n); } console.log(countTo(100000 , 0)) 它仍然失败。 我试过添加'use strict'; 在函数体内部和文件的顶部。 我试过使用–harmony和–harmony-tailcalls 球拍中的function与预期相同: #lang racket (define count-to (lambda (n acc) (cond ((= n 0) acc) (else (count-to (- n 1) (+ […]

在Node.js的ES6中定义它的类中不能调用一个方法

我正在使用Node.js,Express.js和MongoDB制作应用程序。 我正在使用MVC模式,也有单独的路由文件。 我想我做一个控制器类,其中一个方法调用其中声明的另一个方法。 但我似乎无法做到这一点。 我得到“无法读取未定义的属性”。 index.js文件 let express = require('express'); let app = express(); let productController = require('../controllers/ProductController'); app.post('/product', productController.create); http.createServer(app).listen('3000'); ProductController.js文件 class ProductController { constructor(){} create(){ console.log('Checking if the following logs:'); this.callme(); } callme(){ console.log('yes'); } } module.exports = new ProductController(); 当我运行这个我得到以下错误信息: Cannot read property 'callme' of undefined 我已经自己运行这个代码,稍作修改,如下所示。 class ProductController { constructor(){} create(){ […]

为什么在web和nodejs上运行JavaScript会有不同的输出?

我已经更新了我的Node.Js到version 7.6.0 ,另一方面运行谷歌浏览器version 57.0 。 当我运行JavaScript代码片段时,会得到如下两个不同的结果: 'use strict' var obj = { id: "awesome", cool: function coolFn() { console.log(this.id); } }; var id = "not awesome"; obj.cool(); //awsome setTimeout(obj.cool, 100); 结果在铬: awesome not awesome 结果在node.js上: awesome undefined logging到https://nodejs.org/en/docs/es6/我甚至使用了–harmony标志,但是node.js的结果没有改变。

恢复属性键/值

我正在使用–harmony标志在Node.JS v0.11.4中使用ECMAScript 6符号和地图。 考虑以下。 var a = Map(); a.set(Symbol(), 'Noise'); // Prints "1" console.log(a.size); 如果属性由“匿名”符号键标识,那么是否可以检索'Noise'值?