No, you canβt.
The fact is that the prototype property is a constructor property, in this case Foo . If you create an object using a syntax literal such as
var foo = { prototype: {} };
you have a property assigned to an object, not a constructor.
This is a difference, and therefore automatic search for a prototype object will not work when using this literal.
If you want to work with a prototype, you must use the constructor syntax as follows:
var Foo = function () {}; Foo.prototype.foo = 'bar'; var foo = new Foo(); console.log(foo.foo);
As discussed in the comments, it also doesn't work if you try to assign the constructor object to an object in literal syntax: it only works again when using true prototyping.
Hope this helps.
source share