代码如下:
 function Teacher(name, age) {
        this.name = name;
        this.age = age;
    }
    Teacher.prototype.sayName = function() {
        alert(this.name);
    };
    Teacher.prototype.sayHi = function() {
        alert("Hi, I'm " + this.name);
    };
    console.log(Teacher.prototype instanceof Teacher);  // false
    console.log(Teacher.prototype instanceof Object);   // true
    console.log(Teacher.prototype);  // Teacher {sayName: function, sayHi: function}
ps 上面的输出是 chrome。第一个console.log显示Teacher.prototype不是Teacher的实例,但第三条显示Teacher.prototype是Teacher的实例(直觉上),这是矛盾的。
我知道第二个 console.log 是真的,因为 Object.prototype 在 Teacher.prototype 的原型链中,确切地说Teacher.prototype.__proto__ === Object.prototype。因此第一个 console.log 应该输出 false。
但我很困惑为什么第三个 console.log 的输出显示 Teacher.prototype 是 Teacher 的一个实例。谁能为我澄清一下?非常感谢。