[Javascript] function object/custom object prototype confusion

james james at southspace.org
Wed Apr 13 15:34:23 CDT 2005


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 




More information about the Javascript mailing list