本人用作備份
Javascript 的保留關(guān)鍵字(標(biāo)識(shí)符)不可以用作變量、標(biāo)簽或者函數(shù)名。
有些保留關(guān)鍵字是作為 Javascript 以后擴(kuò)展使用。
關(guān)鍵字是嚴(yán)格不允許,而瀏覽器定義的變量名或者類(lèi)名在使用的時(shí)候注意確保作用域
EMCAScript 中的關(guān)鍵字
| break | case | catch | continue | s |
|---|---|---|---|---|
| abstract | arguments | 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 |
'' 標(biāo)記的關(guān)鍵字是 ECMAScript5 中新添加的。*
JavaScript 對(duì)象、屬性和方法
您也應(yīng)該避免使用 JavaScript 內(nèi)置的對(duì)象、屬性和方法的名稱(chēng)作為 Javascript 的變量或函數(shù)名:
| abstract | arguments | boolean | break | byte |
|---|---|---|---|---|
| Array | Date | eval | function | hasOwnProperty |
| Infinity | isFinite | isNaN | isPrototypeOf | length |
| Math | NaN | name | Number | Object |
| prototype | String | toString | undefined | valueOf |
Java 保留關(guān)鍵字
JavaScript 經(jīng)常與 Java 一起使用。您應(yīng)該避免使用一些 Java 對(duì)象和屬性作為 JavaScript 標(biāo)識(shí)符:
| 保留關(guān)鍵字 | - | - | - | -| - |
|:-----------|:-----|:----------|:----------|:-----------------------|
| getClass | java | JavaArray | javaClass | JavaObject |JavaPackage |
Windows 保留關(guān)鍵字
JavaScript 可以在 HTML 外部使用。它可在許多其他應(yīng)用程序中作為編程語(yǔ)言使用。
在 HTML 中,您必須(為了可移植性,您也應(yīng)該這么做)避免使用 HTML 和 Windows 對(duì)象和屬性的名稱(chēng)
作為 Javascript 的變量及函數(shù)名:
| 保留關(guān)鍵字 | - | - | - | - |
|---|---|---|---|---|
| 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 事件句柄
除此之外,您還應(yīng)該避免使用 HTML 事件句柄的名稱(chēng)作為 Javascript 的變量及函數(shù)名。
| 保留關(guān)鍵字 | - | - | - |
|---|---|---|---|
| onblur | onclick | onerror | onfocus |
| onkeydown | onkeypress | onkeyup | onmouseover |
| onload | onmouseup | onmousedown | onsubmit |