Javascript 中的保留字

3 views
Skip to first unread message

gugod

unread,
Jul 22, 2007, 1:34:13 AM7/22/07
to hsinchu.js
偶爾有些時候會把 "class"﹑"default" 這些常用的字拿來做為雜湊的鍵,但其實這兩個字是 Javascript 之中的保留字。因此
有些特別。比如說:

foo.default

在 IE 之中是文法錯誤,必需要改寫為:

foo["default"]

值得注意的是,在 Firefox 中兩種寫法都行。不太確定是否有規範規定這種狀態應有的正確行為。也許正確的做法是產生文法錯誤,而這確實是屬於
Javascript Engine 各自實要決定的事項。

以下列出 Javascript 裡面的保留字做備考(取自 http://javascript.about.com/library/blreserved.htm):


* abstract
* as
* boolean
* break
* byte
* case
* catch
* char
* class
* continue
* const
* debugger
* default
* delete
* do
* double
* else
* enum
* export
* extends
* false
* final
* finally
* float
* for
* function
* goto
* if
* implements
* import
* in
* instanceof
* int
* interface
* is
* long
* namespace
* native
* new
* null
* package
* private
* protected
* public
* return
* short
* static
* super
* switch
* synchronized
* this
* throw
* throws
* transient
* true
* try
* typeof
* use
* var
* void
* volatile
* while
* with

Reply all
Reply to author
Forward
0 new messages