Hi Ben, thanks for the reply!  I have worked with C++ for many years but 
this is my first exposure to javascript.  I'm using the web editor for 
replying to this, so apologies if the formatting gets messed up :)  I'll 
try to do inline quotes as well but not sure how that will turn out, so 
I'll try to space them out to help readability.

I have read over the doc on prototypal inheritance 
here: https://javascript.info/prototype-inheritance 
and https://javascript.info/function-prototype  I assume that covers all 
the important stuff?

- Constructors return an object 
> - The prototype template is used to configure that object's prototype 


Why wouldn't the object's prototype be the instance template?  The object 
returned by the constructor is an instance, right?  And the object's 
prototype would the "template" the instance was configured from, no?   I'm 
starting to suspect that "prototype" and "template" have completely 
different meanings in v8, whereas in standard usage these terms are 
synonyms.  This is where I get confused, I guess....



> What is the difference between a prototype template and an instance 
> template? 
> It's the difference between `this` and `this.__proto__`, or: 
>   function F() { 
>     this.x = 42; 
>   } 
>   F.prototype.y = 1337; 
>
 
Sorry I'm really trying but I'm not sure how to apply your answer to my 
question.  In your example, F.prototype would be the same as the __proto__ 
object for all instances of 'F', right?  If I'm understanding correctly 
(which is doubtful), in v8 parlance that makes F.prototype the instance 
template of F, right? If not, which thing is the instance template? 



> If I have a constructor function that I want to run when the new objects 
> of the class are created, where should that go? 
> FunctionTemplate. Methods are set with 
> FunctionTemplate::PrototypeTemplate(). 
> (Technically you can also set them on the instance template but that's 
> kind of pointless.) 


Oh, why would it be pointless to set a method on an InstanceTemplate?



> Depending on the answers to the previous 3, this question may be moot, 
> but: Is there any reason to have the same function or property on two or 
> more of these "entities"?  FunctionTemplate and Function?  Or Function and 
> PrototypeTemplate? etc.  For example, I have some existing code that is 
> first setting a property (via Set) on the PrototypeTemplate of the 
> FunctionTemplate, then it also sets that same property (with same value) on 
> the FunctionTemplate.  What might be the intent here? 
> Probably to make it available as both a method and a class method: 
> o.m() and F.m() 


OK, that makes sense.  What would the difference be if I set that property 
on the InstanceTemplate instead?  Or to put another way, why would I ever 
set something on an InstanceTemplate instead of a PrototypeTemplate?

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/34bb3dea-a844-402e-86ac-98a06b982cd9o%40googlegroups.com.

Reply via email to