learnajax (1) [Avatar] Offline
#1
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:

objviewer.ObjectViewer.prototype.appendField=function(addNew){
...
}

but, sometimes some functions do not have prototype, like this one:
objviewer.ObjectViewer.addClick=function(e){
...
}

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

Thanks!!
davecrane (149) [Avatar] Offline
#2
Re: Question for usage of prototype in sample code objviewer.js
Hi,

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

HTH

Dave