为什么对原型的这两个引用返回不同的值?

Why do these two references to a prototype return different values

本文关键字:返回 引用 两个 原型 为什么      更新时间:2023-09-26
var fn = function(){};
console.log(fn.prototype == Object.getPrototypeOf(fn));  //false

啊?

Object.getPrototypeOf(fn)将返回function(){},因为这是所有函数的原型。

.prototype属性表示使用fn构造(用new调用)时新对象的方法和属性。

var fn = function (){};
console.log(fn.prototype); // fn {}
console.log(Object.getPrototypeOf(fn)); // function() {}
/*this is like */
console.log(fn.constructor.prototype) // since the constructor is a function...

var child = new fn() 
console.log(Object.getPrototypeOf(child)); // fn {}