问题标签 [ecmascript-harmony]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
171 浏览

javascript - 使用新的 Harmony 直接代理实现 javascript 沙箱

我发现这个with要点是使用和Harmony 直接代理为 3rd-party 代码实现沙箱。它有多大用处?是否可以使用代理实现适当的 javascript 沙箱?这种方法的怪癖和/或缺点是什么?

(我在这个问题中寻找一个纯 JavaScript 的解决方案,所以没有Caja和类似的服务器端项目)

0 投票
1 回答
143 浏览

javascript - 生成器真的具有侵入性吗

据我了解 Javascript 生成器的当前规范,您必须yield明确标记包含 s 的函数。

我想知道这背后的合理性是什么。

如果这是真的,它将迫使人们写:

这意味着,生成器会像癌症一样在代码库中传播。最后,对于开发人员来说,只产生和处理迭代器真的很有趣。

我会发现它更实用,只需定义我想要处理迭代的位置。

如果浏览器必须将yield调用和生成器处理程序(firstfunc, secondfunc, thirdfunc)之间的所有内容转换为Promise / Future形式,那应该自动工作,而不是 Javascript 开发人员的业务。

或者有没有很好的理由不这样做?

0 投票
4 回答
15268 浏览

javascript - Google Chrome 中未定义 Map()

我一直在寻找答案,但我只得到关于谷歌地图 API 的结果。我正在尝试使用 JavaScript 中的映射将整数映射到字符串。在 Firefox 中一切正常,但在 chrome 中,我在控制台中收到一条错误消息:

未捕获的 ReferenceError:未定义地图

下面是一段参考代码:

0 投票
1 回答
5139 浏览

javascript - 类型错误:这是未定义的

当我foo使用定义的对象、它的有效方法和一些参数调用时,它显示: TypeError: this is undefined.

这是什么意思?

我认为this在这里很重要,因为我正在使用apply谁的第一个参数将用作this调用的方法内部。但这里obj是有效的,它甚至不调用所需的方法。甚至在之前就发现了一个错误。

...args意味着任何额外的参数传递给fooafterobj并将method被推入一个args可以被使用的数组中foo

编辑: ...args是有效的。是ES6。

编辑:我的代码看起来非常好。我正在尝试检查被调用的函数是否有问题。对不起,如果是这样的话。

编辑:对不起,问题出在被调用的方法上。我曾说过不一样,但我很困惑。

其中还有另一个回调。

this显然是未定义的,因为它没有引用该对象。

0 投票
2 回答
841 浏览

javascript - Enable harmony proxies at runtime in node.js

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 like https://github.com/tvcutsem/harmony-reflect to work around this, but this still requires the --harmony flag to enable the underlying proxy support, and I want to know whether it's possible to enable that at runtime in a process started without the --harmony flags.

0 投票
4 回答
4542 浏览

javascript - 如何将 --harmony 节点标志添加到 grunt-express

我正在使用 grunt-express 进行本地开发。

这是我的 GruntFile.js

我启动我的本地服务器

咕哝开始

但我需要将 --harmony 标志添加到节点可执行文件中。

我该怎么做?

0 投票
3 回答
1144 浏览

node.js - 节点光纤可以使用 ES6 生成器实现吗?

Wikipedia 建议可以使用生成器来实现协程。这是否意味着可以使用ES6 生成器来实现节点光纤

0 投票
1 回答
271 浏览

javascript - 在 ECMAScript 6 草案中,使用 StopIteration 异常来表示迭代结束的基本原理是什么?

ECMAScript 6 规范草案中StopIteration,使用异常来表示迭代结束而不是使用专用方法(hasNext在 Java/Scala 和MoveNextC# 中)来检查迭代结束的基本原理是什么。

抛开潜在的性能问题不谈,在我看来,异常不应该用于并非真正异常的事情。

0 投票
1 回答
1227 浏览

node.js - jslint + 节点 --harmony

我怎样才能jslint玩得好node --harmony?当我使用和谐标志运行节点时,我收到jslint如下错误:

总而言之,我希望 jslint 能够识别出我正在使用 ES6 扩展。有办法吗?

0 投票
1 回答
937 浏览

javascript - 能否在 node.js/Javascript 中拦截对模块或类的调用

在 PHP 中,每个类都包含一个“神奇”的 __call 函数。使用这个可以动态拦截对一个类的所有调用。例如使用

http://www.php.net/manual/en/language.oop5.overloading.php#object.call

JavaScript/Node.js 中是否有类似的可能?是在模块上(由 require 加载)还是在类上?

更新: 感谢所有评论的人。这在纯 JavaScript 中似乎是不可能的。至少目前。