ECMAScript多个序言指令 [英] ECMAScript multiple Prologue Directives

查看:105
本文介绍了ECMAScript多个序言指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

某些ECMAScript环境允许通过指令序言转换为特殊模式。 ECMAScript 5具有严格使用功能,而其他诸如 asm 具有自己的使用asm。

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 like "use asm".

指令序言是用一种对我的理解水平不甚了解的语言编写的。用多个指令构造指令序言的正确方法是什么?我的直觉是:

The docs on Directive Prologues are written in a language that's a little to obtuse for my comprehension level. What is the correct way to construct a Directive Prologue with multiple Directives? My hunch is its:

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

但我不确定。

推荐答案


构造具有多个指令的指令序言的正确方法是什么?

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

按照指定您已链接


a 指令序言最长的序列 ExpressionStatement 作品的em> 发生在[脚本或函数的开头],并且每个[脚本或函数]完全由 StringLiteral

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.

所以您可以将它们串在一起,所有这些字符串文字声明都是一个指令;并且可以具有特定于实现的含义(仅指定Use-Strict-Directive)。您的直觉是正确的,应该可以:

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

这篇关于ECMAScript多个序言指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆