JavaScript 保留字
在 JavaScript 中,不能将这些保留字用作变量、标签或 函数名称:
| abstract | arguments | await* | boolean |
|---|---|---|---|
| break | byte | case | catch |
| char | class* | const | continue |
| debugger | default | delete | do |
| double | else | enum* | eval |
| export* | extends* | false | final |
| finally | float | for | function |
| goto | if | implements | import* |
| in | instanceof | int | interface |
| let* | long | native | new |
| null | package | private | protected |
| public | return | short | static |
| super* | switch | synchronized | this |
| throw | throws | transient | true |
| try | typeof | var | void |
| volatile | while | with | yield |
标有 * 的单词是 ECMAScript 5 和 6 中的新单词。
删除的保留字
以下保留字已从 ECMAScript 5/6 标准中删除:
| abstract | boolean | byte | char |
|---|---|---|---|
| double | final | float | goto |
| int | long | native | short |
| synchronized | throws | transient | volatile |
不要将这些词用作变量。ECMAScript 5/6 没有完全支持 在所有浏览器中。
JavaScript 对象、属性和方法
您还应该避免使用 JavaScript 内置对象、属性和方法:
| Array | Date | eval | function |
|---|---|---|---|
| hasOwnProperty | Infinity | isFinite | isNaN |
| isPrototypeOf | length | Math | NaN |
| name | Number | Object | prototype |
| String | toString | undefined | valueOf |
Java 保留字
JavaScript 通常与 Java 一起使用。您应该避免使用某些 Java 对象 和属性作为 JavaScript 标识符:
| getClass | java | JavaArray | javaClass |
|---|---|---|---|
| JavaObject | JavaPackage |
其他保留字
JavaScript 可以用作编程 语言在许多应用程序中。
您还应该避免使用 HTML 的名称 和 Window 对象和属性:
| alert | all | anchor | anchors |
|---|---|---|---|
| area | assign | blur | button |
| checkbox | clearInterval | clearTimeout | clientInformation |
| close | closed | confirm | constructor |
| crypto | decodeURI | decodeURIComponent | defaultStatus |
| document | element | elements | embed |
| embeds | encodeURI | encodeURIComponent | escape |
| event | fileUpload | focus | form |
| forms | frame | innerHeight | innerWidth |
| layer | layers | link | location |
| mimeTypes | navigate | navigator | frames |
| frameRate | hidden | history | image |
| images | offscreenBuffering | open | opener |
| option | outerHeight | outerWidth | packages |
| pageXOffset | pageYOffset | parent | parseFloat |
| parseInt | password | pkcs11 | plugin |
| prompt | propertyIsEnum | radio | reset |
| screenX | screenY | scroll | secure |
| select | self | setInterval | setTimeout |
| status | submit | taint | text |
| textarea | top | unescape | untaint |
| window |
HTML 事件处理程序
此外,应避免使用所有 HTML 事件处理程序的名称。
例子:
| onblur | onclick | onerror | onfocus |
|---|---|---|---|
| onkeydown | onkeypress | onkeyup | onmouseover |
| onload | onmouseup | onmousedown | onsubmit |
搜索
阅读量:
收藏数:
点赞数:


0评论