473,323 Members | 1,550 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

prototypes and references

Hi,

A discussion on the YUI page is depending on some speculation and I
know someone here knows the truth. Below is the relevant section. If
you can clarify this confusion I would greatly appreciate it.

Thanks,
Peter
One person wrote:
I'm not entirely sure how browsers handle prototypes, but I strongly
suspect that any item that makes use of a prototype contains
references (function pointers) to the prototype code, and that
overloading is performed simply by overwriting these references.
I responded:

I don't think this is the way it works. I think that if the object
doesn't contain the method then the next place the compiler looks is
in the prototype for the objects class. If it works like you suggested
then if you create an inheritance chain the object would need method
references for all methods in the inheritance chain. I don't think the
guys writing compilers want to work that hard.

Jul 7 '06 #1
4 1140
Hi Peter,

A reference is kept to the prototype. The actual function in the
prototype is not overwritten. When invoking a function it first looks at
the actual object. If that object does not contain the function or
variable, it looks at the prototype's functions and variables (and the
prototype's prototype and so on).

Vincent

pe**********@gmail.com schreef:
Hi,

A discussion on the YUI page is depending on some speculation and I
know someone here knows the truth. Below is the relevant section. If
you can clarify this confusion I would greatly appreciate it.

Thanks,
Peter
One person wrote:
> I'm not entirely sure how browsers handle prototypes, but I strongly
suspect that any item that makes use of a prototype contains
references (function pointers) to the prototype code, and that
overloading is performed simply by overwriting these references.

I responded:

I don't think this is the way it works. I think that if the object
doesn't contain the method then the next place the compiler looks is
in the prototype for the objects class. If it works like you suggested
then if you create an inheritance chain the object would need method
references for all methods in the inheritance chain. I don't think the
guys writing compilers want to work that hard.
Jul 7 '06 #2
Vincent van Beveren wrote:
>
A reference is kept to the prototype. The actual function in the
prototype is not overwritten. When invoking a function it first looks at
the actual object. If that object does not contain the function or
variable, it looks at the prototype's functions and variables (and the
prototype's prototype and so on).
This is what I thought but I wanted some extra confimation. I reread in
Flanagan's JavaScript book (4th ed. p 121) and it confirms this also.

Thanks,
Peter

Jul 7 '06 #3
pe**********@gmail.com wrote:
A discussion on the YUI page is depending on some speculation
and I know someone here knows the truth. Below is the relevant
section. If you can clarify this confusion I would greatly
appreciate it.
<snip>
One person wrote:
> I'm not entirely sure how browsers handle prototypes,
Which is a bad sign as it doesn't take into account that javascript is
used to script more than just browsers and in order to be useful needs
to behave the same in non-browsers as it does in browsers.
> but I strongly suspect that any item that makes use of
a prototype contains references (function pointers) to
the prototype code, and that overloading is performed
simply by overwriting these references.
If that were true you would lose the ability to delete the properties of
an object and by doing so revert to the values of its prototype.
I responded:

I don't think this is the way it works. I think that if
the object doesn't contain the method then the next place
the compiler looks is in the prototype for the objects class.
<snip>

It is misleading to be talking of classes when directly discussing
javascript's actual behaviour, as it has no classes (or it has just one
class, which is much the same thing). The terminology from class-based
languages can be a useful shorthand when implementing concepts that
parallel those of class-based languages, but they tend to get in the way
when discussing the actual mechanism of the prototype-based inheritance
that javascript employs.

The definitive answer is, of course, in the language's specification:-

ECMA 262, 3rd Ed.

Section 13.2.2 the [[Construct]] method of functions (how the
[[Prototype]] is assigned).
Section 8.7.1 the internal GetValue function.
Section 8.6.2.1 the [[Get]] method of native ECMAScript objects.

- and other places. Speculation can be unnecessary when you have
specification.

Richard.
Jul 7 '06 #4
Richard Cornford wrote:
>
It is misleading to be talking of classes when directly discussing
javascript's actual behaviour, as it has no classes (or it has just one
class, which is much the same thing). The terminology from class-based
languages can be a useful shorthand when implementing concepts that
parallel those of class-based languages, but they tend to get in the way
when discussing the actual mechanism of the prototype-based inheritance
that javascript employs.
Very good point.
The definitive answer is, of course, in the language's specification:-

ECMA 262, 3rd Ed.

Section 13.2.2 the [[Construct]] method of functions (how the
[[Prototype]] is assigned).
Section 8.7.1 the internal GetValue function.
Section 8.6.2.1 the [[Get]] method of native ECMAScript objects.
Thanks for these pointers.

Peter

Jul 8 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

145
by: David MacQuigg | last post by:
Playing with Prothon today, I am fascinated by the idea of eliminating classes in Python. I'm trying to figure out what fundamental benefit there is to having classes. Is all this complexity...
7
by: Michele Simionato | last post by:
So far, I have not installed Prothon, nor I have experience with Io, Self or other prototype-based languages. Still, from the discussion on the mailing list, I have got the strong impression that...
14
by: fb | last post by:
Does the C language require you to prototype functions? If it's not required, is it recommended?
7
by: junky_fellow | last post by:
Can a function have two different prototypes ? If not , then how can main() have two different prototypes ? int main(void) and int main argc(int argc, char *argv) I mean to say, if I declare...
1
by: petermichaux | last post by:
Hi, I have searched the archives but didn't find the questions and answers I am looking for. I have been looking at Prototype.js quite a bit lately as I need to create a very small library of...
20
by: Ari Krupnik | last post by:
scripts can add methods to the prototypes of builtin objects in JaavScript. I can assign functions to String.prototype.*, for instance. I want to add a method to Node, but when I try to execute...
7
by: Charles D Hixson | last post by:
I'm sure I've read before about how to construct prototypes in Python, but I haven't been able to track it down (or figure it out). What I basically want is a kind of class that has both class...
73
by: Steph Barklay | last post by:
Hi, I'm currently taking a data structures course in C, and my teacher said that function prototypes are not allowed in any of our code. He also said that no professional programmers use function...
4
by: robtyketto | last post by:
Greetings, I’m writing a research report on justifying disposable prototypes. The problem being there is a wealth of material regarding failures in the IT press and some of these put partial...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.