ECMAScript multiple Prologue Directives

前端 未结 2 694
长情又很酷
长情又很酷 2021-01-14 13:34

Certain ECMAScript environments permit switiching into a special mode by means of a Directive Prologue. ECMAScript 5 has \"use strict\" and others such as asm have their own

2条回答
  •  孤独总比滥情好
    2021-01-14 14:13

    What is the correct way to construct a Directive Prologue with multiple Directives?

    As the spec you linked says,

    a Directive Prologue is the longest sequence of ExpressionStatement productions occurring [at the begin of a script or function] and where each [of them] consists entirely of a StringLiteral.

    So you can just string them together, every of these string-literal-statements is a Directive; and can have an implementation-specific meaning (only the Use-Strict-Directive is specified). Your hunch is correct, this should work:

    "use bar"
    "use strict"; 'use x';
    'use foo';
    

提交回复
热议问题