Javascript 类型错误:';MyClass.MyFunction不是一个函数';ES6/Node 4中的错误消息
我面临一个bug,我可以在node.js 4.0应用程序中使用以下代码复制该bug:Javascript 类型错误:';MyClass.MyFunction不是一个函数';ES6/Node 4中的错误消息,javascript,node.js,ecmascript-6,immutable.js,Javascript,Node.js,Ecmascript 6,Immutable.js,我面临一个bug,我可以在node.js 4.0应用程序中使用以下代码复制该bug: "use strict"; var Immutable = require("immutable"); class AspectType { constructor(htmlLabel) { this.hhtmlLabel = htmlLabel; } htmlLabel() { return this.hhtmlLabel; } } var AspectTypes = Immutable
"use strict";
var Immutable = require("immutable");
class AspectType {
constructor(htmlLabel) { this.hhtmlLabel = htmlLabel; }
htmlLabel() { return this.hhtmlLabel; }
}
var AspectTypes = Immutable.OrderedMap()
.set("C",new AspectType("xxx"))
.set("D",new AspectType("yyy"))
.set("E",new AspectType("zzz"));
for (var retr in AspectTypes.values()) {
console.log(retr.htmlLabel());
}
我收到以下错误消息,为什么
TypeError: retr.htmlLabel is not a function
at Object.<anonymous> (...\testt.js:17:22)
TypeError:retr.htmlabel不是函数
反对。(…\testt.js:17:22)
Pfff
for (var retr of AspectTypes.values()) {
不是
为什么要使函数名与在构造函数中传递的字符串参数相同?这太令人困惑了!你的代码在babel中确实有效。嗯。我没有用巴贝尔,也不想用它…@Willian你注意到了的
和
中的之间的区别吗,这解释了错误的来源?
for (var retr in AspectTypes.values()) {