[thelist] JavaScript Functions and correctly returning values

Tom Dell'Aringa pixelmech at yahoo.com
Thu Aug 15 15:08:01 CDT 2002


Hey all,

I'm just full of stuff today.. I read somewhere that you should
*always* return a value from a function, even if its return false or
null. So question 1 is, is that truly the case? I believe the author
was speaking of "good programming habits" and the like.

Secondly, note the following function:

function Collection() {
  this.length = 0;
  this.add = add;
  return this;
}

This is a constructor function. I've never seen "return this" at the
end of a constructor. It's certainly not required, but does this go
along with my first question? I'm assuming that saying return this
will in fact return the value of all the objects properties.

Of course, the function would have done this anyway. Is using return
adding any speed or effectiveness to the function, or is it just a
"best practice"?

Tom

=====
var me = tom.pixelmech.webDeveloper();

http://www.pixelmech.com/
http://www.maccaws.com/
[Making A Commercial Case for Adopting Web Standards]

__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com



More information about the thelist mailing list