is prtotype an object or a method?

JavaScript and client side scripting.

Moderator: General Moderators

is prtotype an object or a method?

Postby wvoyance » Thu Jun 21, 2012 4:33 am

is prtotype an object or a method?

I think it is a method but the book I am reading, a translation of morrison's book, said it is an object.
User avatar
wvoyance
Forum Contributor
 
Posts: 134
Joined: Tue Apr 17, 2012 8:24 pm

Re: is prtotype an object or a method?

Postby Chris Corbyn » Thu Jun 21, 2012 7:24 am

It is an object. You cannot invoke it. Methods are functions attached to an object. You can invoke them as such. Objects are just containers for data.

JavaScript's prototype object is an object that knows how to construct the object it belongs to. You can add new methods to a "class" by adding them to the prototype object for that class, among other interesting things. JavaScript's object model is a little quirky at first, but is actually very simple once you get used to it.
User avatar
Chris Corbyn
Breakbeat Nuttzer
 
Posts: 13098
Joined: Wed Mar 24, 2004 8:57 am
Location: Melbourne, Australia

Re: is prtotype an object or a method?

Postby Weirdan » Sun Jun 24, 2012 10:43 am

JavaScript's prototype object is an object that knows how to construct the object it belongs to.

That's a constructor, prototype is just that - an object above your current object in the prototype chain.
User avatar
Weirdan
Moderator
 
Posts: 5889
Joined: Mon Nov 03, 2003 7:13 pm
Location: Odessa, Ukraine

Re: is prtotype an object or a method?

Postby wvoyance » Sun Jun 24, 2012 10:52 am

Weirdan wrote:
JavaScript's prototype object is an object that knows how to construct the object it belongs to.

That's a constructor, prototype is just that - an object above your current object in the prototype chain.


so, are you saying a prototype is neither an object nor a method, but a constructor?
User avatar
wvoyance
Forum Contributor
 
Posts: 134
Joined: Tue Apr 17, 2012 8:24 pm

Re: is prtotype an object or a method?

Postby Christopher » Sun Jun 24, 2012 10:00 pm

No, he's not saying that. The first sentence of this article describes it well:

http://en.wikipedia.org/wiki/Prototype- ... rogramming

The rest of the article should answer your questions.
(#10850)
User avatar
Christopher
Site Administrator
 
Posts: 12649
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US


Return to Javascript

Who is online

Users browsing this forum: No registered users and 2 guests

cron