JavaScript保留字
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 新增的. 阅读更多关于JavaScript版本信息在JavaScript 版本一章. 删除保留字 下列保留字已从 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 保留字
在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 新增的.
阅读更多关于JavaScript版本信息在JavaScript 版本一章.
删除保留字
下列保留字已从 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和窗口对象和属性的名称:
| 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 |
交流与评论