PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Dec 18, 2014 10:12 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Thu Jun 21, 2012 4:33 am 
Offline
Forum Contributor
User avatar

Joined: Tue Apr 17, 2012 8:24 pm
Posts: 135
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.


Top
 Profile  
 
PostPosted: Thu Jun 21, 2012 7:24 am 
Offline
Breakbeat Nuttzer
User avatar

Joined: Wed Mar 24, 2004 8:57 am
Posts: 13098
Location: Melbourne, Australia
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.


Top
 Profile  
 
PostPosted: Sun Jun 24, 2012 10:43 am 
Offline
Moderator
User avatar

Joined: Mon Nov 03, 2003 7:13 pm
Posts: 5930
Location: Odessa, Ukraine
Quote:
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.


Top
 Profile  
 
PostPosted: Sun Jun 24, 2012 10:52 am 
Offline
Forum Contributor
User avatar

Joined: Tue Apr 17, 2012 8:24 pm
Posts: 135
Weirdan wrote:
Quote:
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?


Top
 Profile  
 
PostPosted: Sun Jun 24, 2012 10:00 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 12721
Location: New York, NY, US
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)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group