2012-11-12 71 views
146

節點應用已經要求我與和諧的標誌運行節點,如:`node --harmony`做什麼?

node --harmony app.js 

這是什麼和諧的標誌?它做什麼,爲什麼沒有它的應用程序不能運行?

我試過查看節點命令行選項(node --help),但它沒有提供任何細節。節點文檔也沒有任何幫助。

回答

109

打字man node有這樣的和諧標誌:

--harmony_typeof (enable harmony semantics for typeof) 
     type: bool default: false 
--harmony_scoping (enable harmony block scoping) 
     type: bool default: false 
--harmony_modules (enable harmony modules (implies block scoping))  
     type: bool default: false 
--harmony_proxies (enable harmony proxies)  
     type: bool default: false 
--harmony_collections (enable harmony collections (sets, maps, andweak maps)) 
     type: bool default: false 
--harmony (enable all harmony features (except typeof)) 
     type: bool default: false 

所以--harmony是一條捷徑,使所有的和諧功能(如--harmony_scoping--harmony_proxies等等)從this blog post看來,和諧使語言中的新ECMAScript 6功能成爲可能。你的文件不能和諧運行的原因是因爲app.js可能使用了新ECMAScript 6標準的非向後兼容功能(如塊定義,代理,集合,映射等)

+43

值得一提的是[Harmony是用於新ECMAscript的名稱](https://mail.mozilla.org/pipermail/es-discuss/2008-August/006837.html)。 Harmony命名空間包含[該語言的提案]功能(http://wiki.ecmascript.org/doku.php?id=harmony:harmony)。 – eis

+0

非常感謝!現在一切都說得通了。順便說一句。任何想法是什麼等同於Windows中的「man node」? :) – jsalonen

+3

@jsalonen沒有一個,但你可以通過'> node --v8-options'來獲取這裏提到的東西 – eis

0

正如Node文檔,--harmony標誌使ES6

的非穩定,但很快砥部馬廄功能上的Node.js的--harmony標誌的當前行爲是隻啓用上演功能。畢竟,它現在是--es_staging的同義詞。如上所述,這些完成功能尚未被認爲是穩定的。如果您想要保證安全,尤其是在生產環境中,請考慮刪除此運行時標誌,直到它在V8上以及因此在Node.js上默認發貨。如果保持啓用狀態,則應該爲進一步的Node.js升級做好準備,以便在V8更改其語義以更緊密地遵循標準時破壞您的代碼。

0

如果您想在舊版本的nodejs中運行ECMAScript 6功能,可以使用--harmony標誌。 最新版本的節點支持ES6,因此不需要--harmony標誌