Javascript中的保留关键字

什么JavaScript关键字(函数名称,variables等)保留?

我们应该链接到信息的实际来源,而不仅仅是最热门的谷歌命中。

http://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Reserved_Words

JScript 8.0: http : //msdn.microsoft.com/en-us/library/ttyab5c8.aspx

稍后我会查找ECMAScript链接。

这里是我的诗,里面包含了JavaScript中所有的保留关键字,专注于那些现在保持诚实的人,而不仅仅是得分:

Let this long package float, Goto private class if short. While protected with debugger case, Continue volatile interface. Instanceof super synchronized throw, Extends final export throws. Try import double enum? - False, boolean, abstract function, Implements typeof transient break! Void static, default do, Switch int native new. Else, delete null public var In return for const, true, char …Finally catch byte. 

为了补充benc的答案 ,请参阅标准ECMA-262 。 这些是官方的保留字,但只有一个学者忽视了执行尊重标准。 对于最stream行的实现,即firefox和Internet Explorer的保留字,请参阅benc的答案。

EMCAScript-262中的保留字是关键字未来保留字NullLiteralBooleanLiteral关键字

 break do instanceof typeof case else new var catch finally return void continue for switch while debugger function this with default if throw delete in try 

未来保留字

 abstract export interface static boolean extends long super byte final native synchronized char float package throws class goto private transient const implements protected volatile double import public enum int short 

NullLiteral

 null 

BooleanLiteral

 true false 

我只是阅读JavaScript和jQuery中的这个:缺less手册

并非所有这些保留字都会导致所有浏览器出现问题,但最好在命名variables时避开这些名称。

JavaScript关键字: break, case, catch, continue, debugger, default, delete, do, else, false, finally, for, function, if, in, instanceof, new, null, return, switch, this, throw, true, try, typeof, var, void, while, with

保留以备将来使用: abstract, boolean, byte, char, class, const, double, enum, export, extends, final, float, goto, implements, import, int, interface, let, long, native, package, private, protected, public, short, static, super, synchronized, throws, transient, volatile, yield

alert, blur, closed, document, focus, frames, history, innerHeight, innerWidth, length, location, navigator, open, outerHeight, outerWidth, parent, screen, screenX, screenY, statusbar, window 全局variables在浏览器中: alert, blur, closed, document, focus, frames, history, innerHeight, innerWidth, length, location, navigator, open, outerHeight, outerWidth, parent, screen, screenX, screenY, statusbar, window

我在这里做了一些研究,并在这里发布结果: JavaScript中保留的关键字 。 它根据原始规格(即直接从马的嘴巴)列出每个 ECMAScript语言版本的保留关键字。 我find的其他资源都没有做到这一点。

这里是一个浏览器和语言版本不可知的方式来确定一个特定的string是否被JavaScript引擎视为关键字。 积分为这个答案提供了解决scheme的核心。

 function isReservedKeyword(wordToCheck) { var reservedWord = false; if (/^[az]+$/.test(wordToCheck)) { try { eval('var ' + wordToCheck + ' = 1'); } catch (error) { reservedWord = true; } } return reservedWord; } 

目前的答案都没有警告,不pipeES-Dialect,浏览器往往有自己的保留关键字列表,方法等在ES规定的顶部。

例如,IE9禁止使用像addFilterremoveFilter这样的逻辑名( addFilter ,它们是保留的方法)。

请参阅http://www.jabcreations.com/blog/internet-explorer-9以获得更详细的“当前已知”列表,特定于IE9。; 我还没有find任何官方提及他们在MSDN(或其他地方)。

benc的回答非常好,但对于我的两分钱,我喜欢w3schools的页面:

http://www.w3schools.com/js/js_reserved.asp

除了列出由标准保留的关键字之外,它还有一个长长的关键字列表,您应该避免在特定的情况下; 例如,在编写要在浏览器中运行的代码时不使用名称alert 。 它帮助我弄清楚为什么某些单词在我的编辑器中突出显示为关键字,即使我知道它们不是关键字。