js面試題-----原型和原型鏈


題目1:如何判斷一個變量是數組類型

答案:

var arr = [];
arr instanceof Array//true
typeof arr //object  typeof 是無法判斷數組的

題目2:原型鏈繼承的例子(原型鏈繼承,還有很多方法 參考我的js系列繼承的6種方式)

答案:

function Animal(){
     this.eat = function(){
         console.log('animal  eat')

    }

}

function Dog(){
    this.bark = function(){
       console.log('bark')
    
     }

}

Dog.prototype = new Animal();

var hashiqi = new Dog()

題目3:描述new一個對象的過程

答案: ①、創建一個新對象 ②、this指向這個新對象  ③、執行代碼,即對this賦值  ④、返回this

題目4:創建對象的幾種方式(字面量方式、構造函數模式、Object.create())

答案:

 

題目5:原型、構造函數、實例、原型鏈

答案:

 

題目6:instanceof

答案:

題目7:new運算符

答案:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM