learnajax (1) [Avatar] Offline
Hi, this is a great book. I am learning from it...

I have a question about the usage of prototype in the sample code objreview.js.

I found that sometime some functions will use prototype, like this one:


but, sometimes some functions do not have prototype, like this one:

I want to understand when I should use prototype, and when I should not.

davecrane (149) [Avatar] Offline
Re: Question for usage of prototype in sample code objviewer.js

My thinking at the time was very much influenced by my background as a java coder. The basic rule is this:

functions attached to the prototype become methods on the instance of a class/type
functions attached directly to the constructor are static methods.

99% of the time, you'd want to use instance methods