題目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運算符
答案: