There is no real need for void...
If fact, you use void to return a false value whereas there are
several other ways to do it...
for (var i=arr.length, r=0; i-- || (r = r*x,0); r += arr[i]);
for (var i=arr.length, r=0; i-- || (r = r*x)&0; r += arr[i]);
for (var i=arr.length, r=0; i-- || (r = r*x)&&0; r += arr[i]);
And that's if you feel like doing it complicated...
Because you would more likely take the content of void out and put it
after the for loop...
The only real use I ever saw for void is at the end of bookmarklets:
javascript:document.body.style.backgroundColor='pink';
The previous bookmarklet will change the content of the page to 'pink'
for some obscure reason...
javascript:document.body.style.backgroundColor='pink';void 0;
The second one will make your page look beautiful
But as your bookmarklet must be a bit longer, you'll have some
variables and you don't want then global so you'll use a self-invoking
function and it'll work just fine:
javascript:(function(){document.body.style.backgroundColor='pink';}
());
On Jun 9, 2:49 am, Angus Croll <[email protected]> wrote:
> It might be clearer to do this:
>
> function sample(callback) {
> // Do something
> cond ? callback() : // Do something else
>
> }
>
> Here's a function that sums values of an array then multiples total by x.
> void ensures the final multiply exits the loop
>
> for (var i=arr.length, r=0; i-- || void (r = r*x); r += arr[i]);
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]