Page 1 of 1
is prtotype an object or a method?
Posted: Thu Jun 21, 2012 4:33 am
by wvoyance
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.
Re: is prtotype an object or a method?
Posted: Thu Jun 21, 2012 7:24 am
by Chris Corbyn
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.
Re: is prtotype an object or a method?
Posted: Sun Jun 24, 2012 10:43 am
by Weirdan
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.
Re: is prtotype an object or a method?
Posted: Sun Jun 24, 2012 10:52 am
by wvoyance
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?
Re: is prtotype an object or a method?
Posted: Sun Jun 24, 2012 10:00 pm
by Christopher
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.