首页
会员中心
到顶部
到尾部
JavaScript教程

JavaScript 保留词

时间:2020/11/2 14:54:42  作者:  来源:  查看:0  评论:0
内容摘要:JavaScript 保留词JS 性能JS 版本JavaScript 保留词在 JavaScript 中,您不能把这些保留词作为变量、标记或函数名来使用:abstractargumentsawait*booleanbreakbytecasecatchcharclass*const...

JavaScript 保留词

JavaScript 保留词

在 JavaScript 中,您不能把这些保留词作为变量、标记或函数名来使用:

abstractargumentsawait*boolean
breakbytecasecatch
charclass*constcontinue
debuggerdefaultdeletedo
doubleelseenum*eval
export*extends*falsefinal
finallyfloatforfunction
gotoifimplementsimport*
ininstanceofintinterface
let*longnativenew
nullpackageprivateprotected
publicreturnshortstatic
super*switchsynchronizedthis
throwthrowstransienttrue
trytypeofvarvoid
volatilewhilewithyield

用星号标记的关键词是 ECMAScript 5 和 6 中的新词。

您可以在 JS 版本中阅读更多有关不同 JavaScript 版本的内容。

被删除的保留词

以下保留词已被从 ECMAScript 5/6 标准中删除:

abstractbooleanbytechar
doublefinalfloatgoto
intlongnativeshort
synchronizedthrowstransientvolatile

请不要将这些保留词用作变量。并非所有浏览器都完全支持 ECMAScript 5/6。

JavaScript 对象、属性和方法

您还应该避免使用 JavaScript 内建对象的名称、属性和方法:

ArrayDateevalfunction
hasOwnPropertyInfinityisFiniteisNaN
isPrototypeOflengthMathNaN
nameNumberObjectprototype
StringtoStringundefinedvalueOf

Java 保留词

JavaScript 常与 Java 一起使用。您应该避免把某些 Java 对象和属性用作 JavaScript 标识符:

getClassjavaJavaArrayjavaClass
JavaObjectJavaPackage

其他保留词

JavaScript 能够在很多应用程序中被用作编程语言。

您还应该避免使用 HTML 和 Window 对象和属性的名称:

alertallanchoranchors
areaassignblurbutton
checkboxclearIntervalclearTimeoutclientInformation
closeclosedconfirmconstructor
cryptodecodeURIdecodeURIComponentdefaultStatus
documentelementelementsembed
embedsencodeURIencodeURIComponentescape
eventfileUploadfocusform
formsframeinnerHeightinnerWidth
layerlayerslinklocation
mimeTypesnavigatenavigatorframes
frameRatehiddenhistoryimage
imagesoffscreenBufferingopenopener
optionouterHeightouterWidthpackages
pageXOffsetpageYOffsetparentparseFloat
parseIntpasswordpkcs11plugin
promptpropertyIsEnumradioreset
screenXscreenYscrollsecure
selectselfsetIntervalsetTimeout
statussubmittainttext
textareatopunescapeuntaint
window

HTML 事件处理程序

此外您应该避免使用所有 HTML 事件处理程序的名称。

例如:

onbluronclickonerroronfocus
onkeydownonkeypressonkeyuponmouseover
onloadonmouseuponmousedownonsubmit


上一篇:JavaScript 性能
下一篇:JavaScript 版本
相关评论
广告联系QQ:45157718 点击这里给我发消息 电话:13516821613 杭州余杭东港路118号雷恩国际科技创新园  网站技术支持:黄菊华互联网工作室 浙ICP备06056032号