位置:首頁 > 軟件操作教程 > 編程開發(fā) > JavaScript > 問題詳情

JavaScript 檢測原型

提問人:劉團圓發(fā)布時間:2020-11-26

■知識點

使用isPrototypeOf()方法可以判斷該對象是否為參數(shù)對象的原型。isPrototypeOf()是一個原型方法,可以在每個實例對象上調(diào)用。

■實例設計

下面的代碼簡單演示了如何檢測原型對象。

var F = function(){};                                          //構造函數(shù)

var obj = new F();                                             //實例化

var protol = Object.getPrototypeOf( obj );        //引用原型

console.log( protol.isPrototypeOf(obj) );            //true

var proto = Object.prototype;

console.log( proto.isPrototypeOf({}) );               //true

console.log( proto.isPrototypeOf([]) );               //true

console.log( proto.isPrototypeOf(//) );               //true

console.log( proto.isPrototypeOf(function(){}));   //true

console.log( proto.isPrototypeOf(null) );       //false

繼續(xù)查找其他問題的答案?

相關視頻回答
回復(0)
返回頂部