javascript中instanceof、isPrototypeOf、hasOwnProperty、in的使用,請(qǐng)看下邊的示例:
<script type="text/javascript"><!--function Person() {this.name = "ygm";}var p = new Person();alert("對(duì)象p屬于Object類型:" + (p instanceof Object));alert("對(duì)象p屬于Person類型:" + (p instanceof Person));alert("對(duì)象p的原型鏈中是否存在指定類型的原型:" + Person.prototype.isPrototypeOf(p));alert("對(duì)象p的原型鏈中是否存在指定類型的原型:" + Object.prototype.isPrototypeOf(p));alert("對(duì)象實(shí)例是否存在name屬性:" + p.hasOwnProperty("name"));alert("對(duì)象實(shí)例是否存在toString屬性:" + p.hasOwnProperty("toString"));alert("對(duì)象實(shí)例或原型屬性中是否存在name屬性:" + ("name" in p));alert("對(duì)象實(shí)例或原型屬性中是否存在toString屬性:" + ("toString" in p));// --></script><br /><center>如不能顯示效果,請(qǐng)按Ctrl+F5刷新本頁,更多網(wǎng)頁代碼:<a href='http://www.vxbq.cn/' target='_blank'>http://www.vxbq.cn/</a></center>提示:可修改后代碼再運(yùn)行!
上一篇 Windows 組策略無法啟動(dòng)的解決方法
下一篇 Perl 實(shí)現(xiàn)在網(wǎng)頁自動(dòng)下載資源
程序員人生,我編程,我富裕,記住wfuyu網(wǎng),php教程,php學(xué)習(xí),php手冊(cè),CMS模版制作
聲明:本站大部分內(nèi)容是作者原創(chuàng),少部分收集于互聯(lián)網(wǎng)供大家一起學(xué)習(xí),原版權(quán)很多不明,如有侵權(quán)請(qǐng)聯(lián)系本站,謝謝!
粵ICP備14040726號(hào)-1?? 2015-2020 程序員人生 版權(quán)所有