[Project_owners] Is this valid JS?

Didier Ernotte didier at ernotte.com
Wed Mar 15 12:58:33 EST 2006


Hi,

I think that best practices in coding method or function is to have
only  one entry point (easy to do) and only one exit point at the end
of the method of function (avoid return in the middle of the code).

Didier 

--- Paul Tomlin <paul at paultomlin.com> wrote:

> Assuming 'foo' is a function that returns a true/string/object on 
> success, false/null/undefined on failure, is this valid and/or bad
> form?
> 
> function foobar() {
> 	var bar = foo() || return E_FAIL;
> 
> 	// ....
> }
> 
> IE: can I shortcut to a statement rather than an r-value (?)
> 
> There are many times I find myself doing
> 
> var foo = someFunction();
> if (! foo) {
> 	return E_FAIL;
> }
> 
> and thought I might start being a bit more efficient.
> 
> All assuming the failure is a 'normal' mode of operation.
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org
> http://mozdev.org/mailman/listinfo/project_owners
> 



More information about the Project_owners mailing list