似乎Nodejs 0.10.20中的Map已損壞。我用--harmony(包括--harmony_collections標誌)啓動它。
僅供參考,退貨http://dailyjs.com/2012/10/15/preparing-for-esnext/。
以下示例在Firefox 20.0中運行。Nodejs Harmony/ES6中的地圖集合已損壞?
我下面
> var map = new Map([ ["name", "Nicholas"], ["title", "Author"]]);
undefined
> map
{}
所以contsructor初始化似乎沒有工作。 然後我按照Firefox的例子,他們大多不工作:
> console.log(map.has("name")); // true
false
undefined
> console.log(map.get("name")); // "Nicholas"
undefined
undefined
> console.log(map.has("title")); // true
false
undefined
> console.log(map.get("title")); // "Author"
undefined
undefined
> console.log(map.size()); // 2
TypeError: Object # has no method 'size'
at repl:1:17
at REPLServer.self.eval (repl.js:110:21)
at repl.js:249:20
at REPLServer.self.eval (repl.js:122:7)
at Interface. (repl.js:239:12)
at Interface.EventEmitter.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
at Interface._line (readline.js:531:8)
at Interface._ttyWrite (readline.js:760:14)
at ReadStream.onkeypress (readline.js:99:10)
林困惑的是,這些基本的地圖方式不工作。 我有Nodejs版本0.10.20
我不確定你的問題/是/甚至。這是一項發展功能。另外,不要在REPL中使用'console.log()'。結果已經被檢查並以相同的方式傾倒。 –
你需要使用整個數組作爲該代碼中的一個鍵,而不僅僅是一個任意的數組元素...... – dandavis