5
4

1 回答 1

9

Because you've entirely replaced the original prototype object of f with a plain object. It was the original prototype object that held the reference to f via the .constructor property.

The constructor of an object created using object literal syntax will be the Object constructor.

To get it back, you'd need to put it there manually.

f = function() {};
f.prototype = {};
f.prototype.constructor = f;
thing = new f;

This will shadow the .constructor property on in the prototype chain of the new prototype object.

If you delete that property, you'll get Object again.

delete f.prototype.constructor;

console.log(thing.constructor); // Object
于 2012-09-12T19:29:12.790 回答