開始挖掘js與dojo可能踩的坑

來源:互聯網
上載者:User

1. && 與 || 操作符

如果&&左側運算式的值為真值,則返回右側運算式的值;否則返回左側運算式的值。

如果||左側運算式的值為真值,則返回左側運算式的值;否則返回右側運算式的值。

所以不要天真地以為他們始終返回boolean

"abc" && "123"  // "123""" && "123"  // ""

2. 上一個坑看起來dojo 1.x踩了

dojo.isAlien判斷是否是build-in function. 

// summary://Returns true if it is a built-in function or some other kind of//oddball that *should* report as a function but doesn'treturn it && !d.isFunction(it) && /\{\s*\[native code\]\s*\}/.test(String(it)); // Boolean

一些例子。

dojo.isAlien("") // ""dojo.isAlien(0) // 0

更棘手的是,沒有找到可以返回true的例子。比如

dojo.isAlien(alert) // falsedojo.isAlien(isFinite) // false

類似的類型判斷還有一些不太嚴謹的地方。估計是dojo自己也發現這裡坑比較大,這個方法以及其他一些類型判斷在2.0後移除了。

http://dojotoolkit.org/reference-guide/1.9/releasenotes/migration-2.0.html#testing-object-types

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.