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

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

答案:函數

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

題目2:原型鏈繼承的例子(原型鏈繼承,還有不少方法 參考個人js系列繼承的6種方式)this

答案:spa

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一個對象的過程prototype

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

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

答案:對象

 

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

答案:繼承

 

題目6:instanceof

答案:

題目7:new運算符

答案:

相關文章
相關標籤/搜索