【发布时间】:2023-03-25 14:25:01
【问题描述】:
我有这个代码:
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 的原型会破坏打印机对象的继承链?
【问题讨论】:
标签: javascript prototype