JavaScript คำว่าประกาศ
- หน้าก่อนหน้า การทำงานของ JS
- หน้าต่อไป รุ่น JS
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 中的新词。
您可以在 รุ่น JS中阅读更多有关不同 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 และ 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 |
- หน้าก่อนหน้า การทำงานของ JS
- หน้าต่อไป รุ่น JS