6

[First this question may be taking about same concept as How does JavaScript .prototype work?, but has different context.]

I came across this blog which states:

In JavaScript, each object has a property called “prototype”. An object’s prototype allows us adding properties to all instances of that object (even to the existing instances).

As per my understanding so far, the above statement is confusing for beginners as it does not distinguish between "prototype" and "[[Prototype]]". Not all objects have a prototype property, for example:

var myobject = {};
myobject.prototype; // Undefined

I think it would be better if we say:

In JavaScript, each object has an internal property called “[[Prototype]]” that can be seen in some browsers by accessing the non-standard property called “__proto__”. An object’s prototype allows us adding properties to all instances of that object (even to the existing instances). Only functions (hence constructors) have ‘prototype’ property to set that allows us adding properties to all instances of that object made by that function/constructor.

Is this a more accurate description of JavaScript prototypes, or am I missing something? Thanks in advance.

Community
  • 1
  • 1
Praveen Prajapati
  • 969
  • 1
  • 16
  • 21
  • Hi TobSpr.. first thanks a lot...I have gone through above link...but here I want to know if there is some truth in some way what the blog (mentioned in question) is saying or I am missing something. Thanks again. – Praveen Prajapati Aug 13 '13 at 12:39
  • Yes, you have understood it correctly (and that blog is indeed confusing, if not wrong). However, I would avoid the term "instances of an object" but say "objects that inherit from an object". – Bergi Aug 13 '13 at 12:40
  • Thanks a lot Bergi. So you mean to say: " Only functions (hence constructors) have ‘prototype’ property to set that allows us adding properties to all objects that inherit from that function's object"...Is it correct...or please rephrase. – Praveen Prajapati Aug 13 '13 at 12:46
  • 1
    I think this question is a bit more specific than “How does JavaScript .prototype work?” — it’s not a duplicate of that question. I’ve re-edited the title to reflect this, and voted to re-open. – Paul D. Waite Aug 13 '13 at 13:01
  • 2
    @PraveenPrajapati I think this question deserves an answer which provides both technical and historical reasons as to why only functions have a `prototype` property. I'm eagerly waiting for this question to be reopened. In the mean time you might find my blog post on [Why Prototypal Inheritance Matters](http://aaditmshah.github.io/why-prototypal-inheritance-matters/ "Aadit M Shah | Why Prototypal Inheritance Matters") to be an interesting read. – Aadit M Shah Aug 13 '13 at 13:51
  • Thanks a lot Aadit...I visited your blog. It seems it will open new doors to me. Please do answer once this question reopens...that would be quick and helpful for me....Thanks in advance !! – Praveen Prajapati Aug 13 '13 at 13:59
  • I would phrase it like this: "If there are objects that inherit from an object `obj`, object `obj` will have property `prototype`." Or "Only objects that are inherited from, will have property `prototype`." – Zemljoradnik Sep 02 '14 at 20:54

0 Answers0