思考題?
?題目 1. 如何判斷一個(gè)變量是不是數(shù)組?
? ? [] instanceof Array --> true
? ? [] instanceof Object --> true
? ? {} instanceof Object --> true
?題目 2. 手寫一個(gè)簡(jiǎn)易的jQuery,考慮插件和擴(kuò)展性
?題目 3. class的原型本質(zhì)怎么理解
知識(shí)點(diǎn)
? 1. class和繼承
? ? ? ? 聲明一個(gè)類
? ? ? ? class Student {
? ? ? ? ? ? constructor(name,number) {
? ? ? ? ? ? ? ? this.name = name;
? ? ? ? ? ? ? ? this.number = number;
????????????}
? ? ? ? ? ? sayHi() {
? ? ? ? ? ? ? ? console.log(`姓名:${this.name} , 學(xué)號(hào) ${this.number}`)
????????????}
????????}
? ? ? ? 通過類聲明對(duì)象/實(shí)例
? ? ? ? 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. 原型和原型鏈

原型關(guān)系? ??
?· 每個(gè)class都有顯示原型prototype
?· 每個(gè)實(shí)例都有隱式原型__proto__
?· 實(shí)例的__proto__指向?qū)?yīng)class的prototype
基于原型的執(zhí)行規(guī)則
? ? · 獲取屬性xialuo.name 或執(zhí)行方法 xialuo.sayHi() 時(shí)
? ? ? 1.先在自身屬性和方法尋找
? ? ? 2.如果找不到則自動(dòng)去__proto__中查找
原型鏈
