Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple javascript methods calls not invoked in expression

Tags:

javascript

The JavaScript function

function tile(u,v, a,b,c,d) {
  var c0 = tileCorners[a].eval(u,v);
  var c1 = tileCorners[b].eval(u-1,v);
  var c2 = tileCorners[c].eval(u,v-1);
  var c3 = tileCorners[d].eval(u-1,v-1);
  return c0 + c1 + c2 + c3;
}

should be equivalent to

function tile(u,v, a,b,c,d) {
  return
    tileCorners[a].eval(u,v) +
    tileCorners[b].eval(u-1,v) +
    tileCorners[c].eval(u,v-1) +
    tileCorners[d].eval(u-1,v-1);
}

yet the second function always returns undefined (the debugger will not "step into" the calls to eval) whereas the first function behaves correctly. Is there something about having multiple eval method calls in an expression that is wrong?

like image 431
wcochran Avatar asked May 25 '26 01:05

wcochran


1 Answers

You're a victim of the rules of semicolon insertion.

Try:

return tileCorners[a].eval(u,v) +
tileCorners[b].eval(u-1,v) +
tileCorners[c].eval(u,v-1) +
tileCorners[d].eval(u-1,v-1);

Your version is equivalent to:

return;

tileCorners[a].eval(u,v) +
tileCorners[b].eval(u-1,v) +
tileCorners[c].eval(u,v-1) +
tileCorners[d].eval(u-1,v-1);
like image 135
Pointy Avatar answered May 27 '26 13:05

Pointy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!