[Javascript] function object/custom object prototype confusion
Hakan M (Backbase)
hakan at backbase.com
Wed Apr 13 15:43:48 CDT 2005
Try:
Person.prototype.toString = function() {
return this.first + " " + this.last;
}
I try to create all methods/properties of my prototypes in one go. In
that fashion, you could fix it like this:
window.Person.prototype = {
first: '',
last: '',
toString: function() {
this.first + ' ' + this.last;
}
}
Regards,
H
james wrote:
> Hi
>
> I hope this is a simple question!!
>
> I've been following a javascript tutorial
> (http://www.kevlindev.com/tutorials/javascript/inheritance/)
>
> right at the start, in the first few lines of the tutorial are some
> lines of example code:
>
> // constructor function
> function Person(first, last) {
> this.first = first;
> this.last = last;
> }
>
> // instance person of class Person
> var person = new Person("John", "Dough");
>
> // ???
> Person.prototype.toString() {
> return this.first + " " + this.last;
> }
>
> // example
> alert( person.toString() ); // displays "John Dough"
> alert( person ); // same result since alert calls toString()
> --------------------
>
> but, I get an error for the line beginning Person.prototype.toString()
> which looks wrong to me anyway (is a function or object literal?)
>
> can anyone with a bit more experience just take a quick peak and put my
> out of my doubtful misery?
>
> James
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
>
More information about the Javascript
mailing list