Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
385 views
in Technique[技术] by (71.8m points)

javascript - What does `node --harmony` do?

A node application has required me to run node with a harmony flag, like:

node --harmony app.js

What is this harmony flag? What does it do and why can't the app run without it?

I've tried looking into node command-line options (node --help), but it doesn't provide any details either. Node docs weren't of any help either.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Typing man node has this on the harmony flag:

 --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

So --harmony is a shortcut to enable all the harmony features (e.g. --harmony_scoping, --harmony_proxies, etc.) From this blog post, it seems harmony enables new ECMAScript 6 features in the language. The reason your file won't run without harmony is because app.js is probably using non-backward compatible features from the new ECMAScript 6 standard (like block scoping, proxies, sets, maps, etc.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...