自强学堂
自强学堂:学习、分享、让你更强!
Javascript 教程HTMLCSSJAVASCRIPTJQUERYSQLPHPBOOTSTRAPANGULARXML
 

JavaScript 保留关键字

在JavaScript中,一些保留关键字不能用作变量名或函数名。


JavaScript 保留关键字

Javascript的保留字不可以用作变量,函数名,对象名等,有些保留关键字是作为Javascript以后扩展使用。

abstractelseinstanceofsuper
booleanenumintswitch
breakexportinterfacesynchronized
byteextendsletthis
casefalselongthrow
catchfinalnativethrows
charfinallynewtransient
classfloatnulltrue
constforpackagetry
continuefunctionprivatetypeof
debuggergotoprotectedvar
defaultifpublicvoid
deleteimplementsreturnvolatile
doimportshortwhile
doubleinstaticwith


Window对象保留关键字

除此之外,你应该避免使用 Window 对象名,方法及属性作为Javascript的变量或函数名:

alertframesouterHeight
allframeRateouterWidth
anchorfunctionpackages
anchorsgetClasspageXOffset
areahasOwnPropertypageYOffset
Arrayhiddenparent
assignhistoryparseFloat
blurimageparseInt
buttonimagespassword
checkboxInfinitypkcs11
clearIntervalisFiniteplugin
clearTimeoutisNaNprompt
clientInformationisPrototypeOfpropertyIsEnum
closejavaprototype
closedJavaArrayradio
confirmJavaClassreset
constructorJavaObjectscreenX
cryptoJavaPackagescreenY
DateinnerHeightscroll
decodeURIinnerWidthsecure
decodeURIComponentlayerselect
defaultStatuslayersself
documentlengthsetInterval
elementlinksetTimeout
elementslocationstatus
embedMathString
embedsmimeTypessubmit
encodeURInametaint
encodeURIComponentNaNtext
escapenavigatetextarea
evalnavigatortop
eventNumbertoString
fileUploadObjectundefined
focusoffscreenBufferingunescape
formopenuntaint
formsopenervalueOf
frameoptionwindow


HTML 事件句柄

同样你应该避免使用HTML事件句柄来作为Javascript的变量及函数名:

onbeforeunloadondragdroponkeyuponmouseover
onbluronerroronloadonmouseup
ondragdroponfocusonmousedownonreset
onclickonkeydownonmousemoveonsubmit
oncontextmenuonkeypressonmouseoutonunload