Quantcast
Channel: December 2008 – Gea-Suan Lin's BLOG
Viewing all articles
Browse latest Browse all 10

jQuery 不再使用 browser-detecting 的技巧

$
0
0

Twitter 上看到 John Resig 的訊息,說 jQuery 不再使用 browser detecting 的技巧,完全改用 Object detecting:「They said it couldn't be done: jQuery no longer uses any browser/useragent sniffing! http://bit.ly/eXrP

Browser detecting 在 ppk 的「Browser detect」這篇文章裡有提到,經常被用於 (且誤用於) 功能的判斷。比較好的方法是 Object detecting

譬如說,目前 Firefox 3 支援 getElementsByClassName(),但 Firefox 2 並不支援。如果你要使用這個功能,應該利用 object detecting 這樣寫:

if (document.getElementsByClassName) {
    // do something with getElementsByClassName
} else {
    // use getElementsByTagName to emulate it
}

而非用 browser detecting:

if (firefox3) {
    // do something with getElementsByClassName
} else {
    // ...
}

除了程式碼比較合理 (乾淨) 外,這樣寫出來的 code 也比較 future proofing。這點可以參考 John Resig 的「Future-Proofing JavaScript Libraries」。


Viewing all articles
Browse latest Browse all 10

Trending Articles


Vimeo 10.7.1 by Vimeo.com, Inc.


UPDATE SC IDOL: TWO BECOME ONE


KASAMBAHAY BILL IN THE HOUSE


Girasoles para colorear


Presence Quotes – Positive Quotes


EASY COME, EASY GO


Love with Heart Breaking Quotes


Re:Mutton Pies (lleechef)


Ka longiing longsem kaba skhem bad kaba khlain ka pynlong kein ia ka...


Vimeo 10.7.0 by Vimeo.com, Inc.


FORECLOSURE OF REAL ESTATE MORTGAGE


FORTUITOUS EVENT


Pokemon para colorear


Sapos para colorear


Smile Quotes


Letting Go Quotes


Love Song lyrics that marks your Heart


RE: Mutton Pies (frankie241)


Hato lada ym dei namar ka jingpyrshah jong U JJM Nichols Roy (Bah Joy) ngin...


Long Distance Relationship Tagalog Love Quotes