我有這樣的代碼:重置Javascript中的原型。爲什麼它會破壞原型繼承鏈?
function PrintStuff(docs) {
this.docs = docs;
}
PrintStuff.prototype.print = function() {
console.log(this.docs)
}
var printer = new PrintStuff("Hello World");
printer.print()
console.log(Object.getPrototypeOf(printer))
console.log(PrintStuff.prototype)
console.log(printer instanceof(PrintStuff))
//true
PrintStuff.prototype = {}
console.log(printer instanceof(PrintStuff))
//false
- 什麼樣的方法是的instanceof?爲什麼不在對象上調用?
- 爲什麼設置PrintStuff的原型會銷燬打印機對象的繼承鏈?
太棒了,但是你的意思是「逆轉它」呢? – Jwan622
@ Jwan622指我的編輯 – sahbeewah