Short version :
Yes. The prototype chain cannot be configured or modified by assigning the prototype property to the object. You cannot set up inheritance by creating an object with an object literal and then providing it with a property called prototype . Such a property will be called prototype , but will not be considered for prototype inheritance.
Longer:
If you access the undefined property, this object inheritance chain is checked. So, if obj['prop'] is undefined , then obj.prototype['prop'] will be checked. In many browsers, the prototype property is implemented internally as the __proto__ property, but this does not apply to the point. Rather, the fact is that if any property is undefined , an object prototype is checked for this property.
As people noted in the comments, it is only possible to endow an object with a prototype that provides the inheritance described above, assigning this object to a property of the prototype function, and then using this function as a constructor.
But the prototype property of the object created by calling the constructor is not object.hasOwnProperty('prototype') . On the other hand, if you assign the prototype property to an object, then this object will be object.hasOwnProperty('prototype') , but then object.prototype will have nothing to do with the prototype chain - it will be just a regular property and will be called by prototype .
To demonstrate this:
var foo = {}; foo.prototype = {bar: 'hello'}; console.log(foo.bar); // undefined console.log(foo.prototype); // Object {bar: "hello"} console.log(foo.hasOwnProperty('prototype')); // true var Foo = function() {}; Foo.prototype = {bar: 'hello'}; var f = new Foo; console.log(f.bar); // 'hello'; console.log(f.hasOwnProperty('bar')); // false console.log(f.prototype); // undefined console.log(f.hasOwnProperty('prototype')); // false
source share