思考題?
?題目 1. 如何判斷一個變量是不是數組毒坛?
? ? [] instanceof Array --> true
? ? [] instanceof Object --> true
? ? {} instanceof Object --> true
?題目 2. 手寫一個簡易的jQuery,考慮插件和擴展性
?題目 3. class的原型本質怎么理解
知識點
? 1. class和繼承
? ? ? ? 聲明一個類
? ? ? ? class Student {
? ? ? ? ? ? constructor(name,number) {
? ? ? ? ? ? ? ? this.name = name;
? ? ? ? ? ? ? ? this.number = number;
????????????}
? ? ? ? ? ? sayHi() {
? ? ? ? ? ? ? ? console.log(`姓名:${this.name} , 學號 ${this.number}`)
????????????}
????????}
? ? ? ? 通過類聲明對象/實例
? ? ? ? const xialuo = new Student("夏洛",100);
? ? ? ? console.log(xialuo.name,xialuo.number)
? ? ? ? xialuo.sayHi();
繼承語法
父類
class People {
? ? constructor (name) {
? ? ? ? this.name = name;
????}
? ? eat() {
? ? ? ? console.log(`${this.name} 在吃飯`)
????}
}
子類
class Student extends People?
? ? constructor(name,number) {
? ? ? ? super(name)
? ? ? ? this.number = number
????}
? ? sayHi() {
? ? ? ? console.log(`$(this,name)?打了招呼`)
????}? ??
}
?2. 類型判斷instanceof
? ? [] instanceof Array --> true
? ? [] instanceof Object --> true
? ? {} instanceof Object --> true
? 3. 原型和原型鏈
原型關系? ??
?· 每個class都有顯示原型prototype
?· 每個實例都有隱式原型__proto__
?· 實例的__proto__指向對應class的prototype
基于原型的執(zhí)行規(guī)則
? ? · 獲取屬性xialuo.name 或執(zhí)行方法 xialuo.sayHi() 時
? ? ? 1.先在自身屬性和方法尋找
? ? ? 2.如果找不到則自動去__proto__中查找