ECMAScript Multiple Prologue Directives

Some ECMAScript environments allow you to switch to special mode using the Prologue directive. ECMAScript 5 uses strict, while others, such as asm , have their own use asm.

Documents for Directory Prologs are written in a language that is a little dumb for my level of understanding. What is the correct way to create a directory prolog with multiple directives? My hunch is this:

function(){ "use foo"; "use bar"; } 

But I'm not sure.

+3
source share
2 answers

What is the correct way to create a directory prolog with multiple directives?

Since the spec you linked says:

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

Thus, you can simply group them together, each of these string literals is a directive; and may have a specific implementation value (only the Use-Strict directive is specified). Your guess is correct, this should work:

 "use bar" "use strict"; 'use x'; 'use foo'; 
+1
source

Since no one answered this, but I found the answer, and this was confirmed in the comment, I answer my question to close it.

Yes, to use several directives in the prolog, list them one by one like this:

 function(){ "use foo"; "use bar"; } 

or

 function(){ "use foo"; "use bar"; } 
+1
source

All Articles