JavaScript 保留关键字
在JavaScript中,一些保留关键字不能用作变量名或函数名。
JavaScript 保留关键字
Javascript的保留字不可以用作变量,函数名,对象名等,有些保留关键字是作为Javascript以后扩展使用。
| abstract | else | instanceof | super |
| boolean | enum | int | switch |
| break | export | interface | synchronized |
| byte | extends | let | this |
| case | false | long | throw |
| catch | final | native | throws |
| char | finally | new | transient |
| class | float | null | true |
| const | for | package | try |
| continue | function | private | typeof |
| debugger | goto | protected | var |
| default | if | public | void |
| delete | implements | return | volatile |
| do | import | short | while |
| double | in | static | with |
Window对象保留关键字
除此之外,你应该避免使用 Window 对象名,方法及属性作为Javascript的变量或函数名:
| alert | frames | outerHeight |
| all | frameRate | outerWidth |
| anchor | function | packages |
| anchors | getClass | pageXOffset |
| area | hasOwnProperty | pageYOffset |
| Array | hidden | parent |
| assign | history | parseFloat |
| blur | image | parseInt |
| button | images | password |
| checkbox | Infinity | pkcs11 |
| clearInterval | isFinite | plugin |
| clearTimeout | isNaN | prompt |
| clientInformation | isPrototypeOf | propertyIsEnum |
| close | java | prototype |
| closed | JavaArray | radio |
| confirm | JavaClass | reset |
| constructor | JavaObject | screenX |
| crypto | JavaPackage | screenY |
| Date | innerHeight | scroll |
| decodeURI | innerWidth | secure |
| decodeURIComponent | layer | select |
| defaultStatus | layers | self |
| document | length | setInterval |
| element | link | setTimeout |
| elements | location | status |
| embed | Math | String |
| embeds | mimeTypes | submit |
| encodeURI | name | taint |
| encodeURIComponent | NaN | text |
| escape | navigate | textarea |
| eval | navigator | top |
| event | Number | toString |
| fileUpload | Object | undefined |
| focus | offscreenBuffering | unescape |
| form | open | untaint |
| forms | opener | valueOf |
| frame | option | window |
HTML 事件句柄
同样你应该避免使用HTML事件句柄来作为Javascript的变量及函数名:
| onbeforeunload | ondragdrop | onkeyup | onmouseover |
| onblur | onerror | onload | onmouseup |
| ondragdrop | onfocus | onmousedown | onreset |
| onclick | onkeydown | onmousemove | onsubmit |
| oncontextmenu | onkeypress | onmouseout | onunload |

