Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #23464

Re: Relationship between .prototype and [[prototype]]

Message-ID <1984124.lNXhnOP79H@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2014-03-08 20:24 +0100
Subject Re: Relationship between .prototype and [[prototype]]
Newsgroups comp.lang.javascript
References <12769af9-a7a9-4f26-826f-5d4a62de4466@googlegroups.com>

Show all headers | View raw


Walter Milner wrote:

> I think that when you define a function func, an object called
> func.prototype is created, and func's prototype property points to it.

Incorrect.  Objects have identity, not name (until they are given a naming 
property).  Functions are objects that have a “prototype” property (created 
upon creation of the Function instance).  The initial value of that property 
is a reference to an Object instance.

> But also func has an internal [[prototype]] property which links to
> Function.prototype.

Function instances have an internal [[Prototype]] property whose value is a 
reference to the same object as referred to by the initial value of the 
“Function.prototype” property.

<http://ecma-international.org/ecma-262/5.1/#sec-13.2>

> Why? What is the idea behind this process?

WLOG, every ECMASCript object has a prototype chain which is identified by 
the object's internal [[Prototype]] property.  But as that property is 
*internal*, it is not as such available to user code, by contrast to the the 
“Function.prototype” property whose initial value refers to the same object.

So by adding properties to the object referred to by “Function.prototype” 
aso., you can have all Function instances inherit new properties, especially 
new methods.  There are several applications for this; see e.g. 
<http://PointedEars.de/wsvn/JSX/trunk/object.js> for examples.

Different to that, you can add properties to the object referred by the 
“prototype” property of Function instances; only objects having this object 
in their prototype chain (in general, objects created by calling this 
function as constructor) inherit those properties.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Relationship between .prototype and [[prototype]] Walter Milner <w.w.milner@gmail.com> - 2014-03-08 08:43 -0800
  Re: Relationship between .prototype and [[prototype]] Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-08 20:24 +0100
  Re: Relationship between .prototype and [[prototype]] John Harris <niam@jghnorth.org.uk.invalid> - 2014-03-09 11:33 +0000
  Re: Relationship between .prototype and [[prototype]] John Harris <niam@jghnorth.org.uk.invalid> - 2014-03-09 11:42 +0000

csiph-web