Javascript: besides “use strict”, which other “use” directives are there?

我怕爱的太早我们不能终老 提交于 2019-12-06 02:36:55

问题


Besides use strict, which other use directives are there?


回答1:


Some more examples that can be in the “directive prologue” (a section potentially usable by JavaScript engines):

  • 'use strict';
  • 'use asm';
    Mozilla's asm.js is a subset of the language, geared towards crunching numbers.
  • 'use stricter';
    Google's SoundScript. For fast OOP
    Has also some modes like:
    • 'use stricter+types';
    • http://www.2ality.com/2015/02/soundscript.html
  • 'use babel';
    Used in Atom.io. (Was previously: 'use 6to5';)

A tweet by Jeremy Ashkenas suggests some further use of + and - prefixes in the same 'use ...'; string ('use stricter +types -tco +jsx +asm +es2019-pre';), but that seems to contradict the spec (further clarified in kangax's answer and Bergi's answer).




回答2:


In case it's still of interest to anyone, I just ran across a "use asm" directive, for use with asm.js.

So it seems like there may be additional "use" options added over time.




回答3:


Although it isn't a declarative like "use strict";, the next version of ECMAScript (codenamed Harmony) will apparently have an opt-in capability you can use in the <script> tag.

From this article:

  • opt-in via MIME type in script tag: <script type="application/javascript;version=next"> (where “next” is a placeholder for something that has still to be determined)

The article is an overview of this presentation by David Herman, which is very much worth watching.



来源:https://stackoverflow.com/questions/6999768/javascript-besides-use-strict-which-other-use-directives-are-there

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!