Hi Emeka,

'prototype' is an attribute that all functions get (by default it's
value is set to Object prototype) The confusing thing is that this
value has nothing to do with the prototype of that function - instead
it is the value that will be assigned to as the prototype of any
instance created if using this function as a constructor

'__proto__' on the other hand represents the actual prototype of an
instance. It's a non-standard approach and is only supported on some
browsers. The ES5 standard approach for retrieving an object's
prototype is Object.getPrototypeOf(obj) but this is not supported in
IE<9

For more info I will shamelessly plug my blog post on the topic ;-)

http://javascriptweblog.wordpress.com/2010/06/07/understanding-javascript-prototypes/


On Dec 29, 3:57 am, Sergio Cinos <[email protected]> wrote:
> I would add:
>
> To set the prototype of an object, you modify the 'prototype' property
> of its constructor function. To get access to the prototype you can
> use myFunction.prototype or myInstance.__proto__.
>
> //Constructor function
> var myFunction = function() { /*...*/ }
> myFunction.prototype.myProperty = 'myValue';
>
> //Instance
> var myInstance = new myFunction();
> myInstance.myProperty === 'myValue'; //true
>
> //Access to prototype
> myFunction.prototype === myInstance.__proto__ ===
> myInstance.constructor.prototype; //true
>
> Happy new year for everyone!
> --
> S.Cinos
> JavaScript Developer at Tuenti.com
>
> 2010/12/29 Lasse Reichstein <[email protected]>:
>
>
>
> > On Wed, 29 Dec 2010 08:25:33 +0100, Emeka <[email protected]> wrote:
>
> >> Is Prototype JavaScript's way of solving Expression Problem? And what is
> >> really the difference between __proto__ and Prototype?
>
> > That depends on what you mean by "Prototype".
> > The internal [[Prototype]] link of objects is a way to inherit (and thereby
> > share)
> > properties of other objects. It can be used to add new functionality to an
> > unknown
> > number of existing objects, by assigning the functionality to their shared
> > prototype,
> > and that way it can be used to solve the Expression Problem. It just
> > requires that
> > the Expressions all inherit from a shared prototype object.
>
> > The non-standard __proto__ property is some Javascript engines' way of
> > reflecting the
> > internal [[Prototype]] property, making it accessible for both reading and
> > writing.
> > It's not-standard and not supported by all engines.
>
> > /L
>
> > --
> > To view archived discussions from the original JSMentors Mailman list:
> > http://www.mail-archive.com/[email protected]/
>
> > To search via a non-Google archive, visit here:
> >http://www.mail-archive.com/[email protected]/
>
> > To unsubscribe from this group, send email to
> > [email protected]

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to