Subject: Need help with inheritance
Posted By: filip Post Date: 8/17/2006 8:32:26 AM
Hi!

On page 108, you write "this.newMethod = ClassA;"

However, on page 109, you write "ClassB.prototype = new ClassA();"

Could you please explain why you have the new keyword in the second case, and no new keyword in the first place.

Please help help help

Thanks :)

Reply By: nzakas Reply Date: 8/25/2006 9:38:47 PM
Filip,

The "new" operator is used to instantiate an instance of an object. So "new ClassA()" creates a new object of the type ClassA. Without "new", ClassA is just a pointer to a function.

Nicholas C. Zakas
Author, Professional JavaScript for Web Developers (ISBN 0764579088)
http://www.nczonline.net/

Go to topic 48673

Return to index page 193
Return to index page 192
Return to index page 191
Return to index page 190
Return to index page 189
Return to index page 188
Return to index page 187
Return to index page 186
Return to index page 185
Return to index page 184