该instanceof运营商应该看看样机,不是吗?在对象的原型发生变化后,为什么不改变它的答案?示例如下:
// The .prototype of objects created with 'new MyKlass'
// is MyKlass.prototype
var MyKlass = function(name, age) {
this.name = name;
this.age = age;
}
var xx = new MyKlass('xx', 20);
console.log(xx instanceof MyKlass); // true, OK
xx.prototype = new String('s');
console.log(xx instanceof MyKlass); // also true, WHY???
Run Code Online (Sandbox Code Playgroud)