我有这样的代码:重置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