你不知道的js之原型鏈繼承
阿新 • • 發佈:2021-08-11
來來來,總結一波ES5的原型繼承
Function.__proto__ === Function.prototype //true 特殊
Function.__proto__ === Object.__proto__ //true
Object.__proto__.__proto__ === Object.prototype //true
Array.__proto__ === Function.prototype //true
String.__proto__ === Function.prototype //true
Number.__proto__ === Function.prototype //true
Boolean.__proto__ === Function.prototype //true
(123).__proto__ === Number.prototype //true會形成包裝類,和new Number(123)一樣
("123").__proto__ === String.prototype //true
(true).__proto__ === Boolean.prototype //true
([]).__proto__ === Array.prototype //true
Number.prototype.__proto__ === Object.prototype //true
String.prototype.__proto__ === Object.prototype //true
Boolean.prototype.__proto__ === Object.prototype //true
Array.prototype.__proto__ === Object.prototype //true
其實Number.prototype就是一個物件,而物件例項的__proto__指向Object.prototype
({}).__proto__ === Object.prototype //true 特殊