ecmascript-harmony

ECMAScript 6's function.name property

﹥>﹥吖頭↗ 提交于 2021-02-10 03:21:41
问题 Quick question: what's the correct result for this code: let f = function(){}; let n = f.name; //"" or "f"? According to the compat table, n should have the value "f" . However, the mozilla docs say that it should return an empty string. Which one is correct? 回答1: Since ECMAScript 6 is currently in draft state, the answer below may become outdated sometime in the future. That being said, referencing the spec draft: Anonymous functions objects that do not have a contextual name associated with

Intellij Idea Ecmascript Harmony modules syntax

萝らか妹 提交于 2021-02-07 06:27:05
问题 Im using Intellij Idea for some ES Harmony app. With modules syntax I want my IDE to do not highlight this as errors: import $ from "jquery"; I have turned ES Harmony support in project settings, but it does not help. Thanks! 回答1: In case somebody here is still experiencing Issues with ECMAScript 6, you have to enable it in IntelliJ. and after activating ecmascript, set it as JavaScript Language Version: 回答2: Try an EAP version, it technically has support but it is not currently working for

How check if Google Chrome has #enable-javascript-harmony turned on

喜你入骨 提交于 2021-01-28 12:09:27
问题 I'm trying to check if the user's from Google Chrome has activate the flag #enable-javascript-harmony. I have no idea how to do it. Any help will be appreciate. 回答1: Chrome flag enable-javascript-harmony turns on the V8 switch --harmony . You can check if it is enabled by testing some ES Next functions from http://node.green (with a flag in the first column), e.g.: const regexGreekSymbol = /\p{Script=Greek}/u; regexGreekSymbol.test('π'); This returns true when ES Harmony is turned on and

Harmony proxy, detect whether property was accessed or called

心已入冬 提交于 2020-07-22 21:40:24
问题 Is there a way using Proxy to detect if a property was executed, or was it just accessed? 'use strict'; require('harmony-reflect'); var Stub = { method: function (a) { console.log('q' + a + this.q); } }; var ProxiedLibrary = { get: function (target, name, receiver) { if (name in target) { return target[name]; } if (MAGIC_EXPRESSION) { return function() { return 'Return from nonexistent function!'; }; } return 'Property ' + name + ' is drunk and not available at the moment'; } }; var Library =

Methods in ES6 objects: using arrow functions

女生的网名这么多〃 提交于 2020-06-01 06:22:13
问题 In ES6, both of these are legal: var chopper = { owner: 'Zed', getOwner: function() { return this.owner; } }; and, as shorthand: var chopper = { owner: 'Zed', getOwner() { return this.owner; } } Is it possible to use the new arrow functions as well? In trying something like var chopper = { owner: 'John', getOwner: () => { return this.owner; } }; or var chopper = { owner: 'John', getOwner: () => (this.owner) }; I get a error messages suggesting that the method does not have access to this . Is

node.js / ES6 / class creation : SyntaxError: Unexpected reserved word

两盒软妹~` 提交于 2020-01-20 03:57:26
问题 I try to create a class on my node.js / express app. It works in basic js / prototype mode such as : function MyClass() { /* constructor code */ }; MyClass.prototype.myMethod = function() { /* method code */ }; module.exports = MyClass; But I want to do use the class, constructor, extends, ... keywords. I've try that : class MyClass { constructor() { /* constructor code */ } myMethod() { /* method code */ } } But it doesn't work, the error is : class MyClass { ^^^^^ SyntaxError: Unexpected

node.js / ES6 / class creation : SyntaxError: Unexpected reserved word

霸气de小男生 提交于 2020-01-20 03:57:07
问题 I try to create a class on my node.js / express app. It works in basic js / prototype mode such as : function MyClass() { /* constructor code */ }; MyClass.prototype.myMethod = function() { /* method code */ }; module.exports = MyClass; But I want to do use the class, constructor, extends, ... keywords. I've try that : class MyClass { constructor() { /* constructor code */ } myMethod() { /* method code */ } } But it doesn't work, the error is : class MyClass { ^^^^^ SyntaxError: Unexpected

JavaScript sets and value objects [duplicate]

会有一股神秘感。 提交于 2020-01-05 11:25:08
问题 This question already has answers here : user defined object equality for a set in harmony (es6) (2 answers) Closed 4 years ago . I want to create a set of value objects in JavaScript. The problem is that in JavaScript equality is based on identity. Hence, two different objects with the same value will be treated as unequal: var objects = new Set; objects.add({ a: 1 }); objects.add({ a: 1 }); alert(objects.size); // expected 1, actual 2 How do you work around this problem? 回答1: Use JSON

JavaScript sets and value objects [duplicate]

给你一囗甜甜゛ 提交于 2020-01-05 11:22:15
问题 This question already has answers here : user defined object equality for a set in harmony (es6) (2 answers) Closed 4 years ago . I want to create a set of value objects in JavaScript. The problem is that in JavaScript equality is based on identity. Hence, two different objects with the same value will be treated as unequal: var objects = new Set; objects.add({ a: 1 }); objects.add({ a: 1 }); alert(objects.size); // expected 1, actual 2 How do you work around this problem? 回答1: Use JSON

Enable harmony proxies at runtime in node.js

醉酒当歌 提交于 2020-01-05 03:08:12
问题 I have a little RPC library for node, and right now it uses harmony proxies for remote objects if they are available (by checking for the existence of a Proxy global). I'd like to be able to turn harmony proxies on at runtime, that is, in a node process that was not started with the --harmony-proxy flag. Is this possible? I understand that there are good reasons not to do this, and I don't really care :-P EDIT As pointed out in the answers, node.js proxies use an older spec. I can use a shim