Quote:
Originally Posted by WhiteDragon
PHP Code:
temp.distance = function (x1, y1, x2, y2) {
return( ((x2 - x1)^2 + (y2 - y1)^2)^.5 );
};
echo(temp.distance(2, 2, 1, 1));
Anonymous functions can unfortunately not be executed in the same statement they are declared in.
|
I may have been gone for a while (and not to nitpick or jump on the bandwagon...), but this is wrong. It is not as pretty as javascript to pull it off, but it can be done.
Quote:
|
Originally Posted by Douglas Crockford on switch Fall Through
Someone once wrote to me once suggesting that JSLint [his javascript "checker"] should give a warning when a case falls through into another case. He pointed out that this is a very common source of errors, and it is a difficult error to see in the code. I answered that that was all true, but that the benefit of compactness obtained by falling through more than compensated for the chance of error.
Then next day, he reported that there was an error in JSLint. It is misidentifying an error. I investigated and it turned out that I had a case that was falling through. In that monent, I achieved enlightenment. I no longer use intentional fall throughs. That discipline makes it much easier to find the unintentional fall throughs.
|
Just because Crockford messes up doesn't mean no one should be allowed to benefit from the usefulness of
switch. S'all I'm sayin'.
A few more things: javascript is a language in which appending the bracket at the end of a function is highly recommended because it has a sort of auto-complete where it puts a semicolon at the end of any line that a parser thinks is a complete statement. Placing a bracket at the end of a line avoids any confusion. GraalScript does not have this issue. Go hog wild, throw that bracket anywhere you like (where syntax allows).
The argument that X language uses Y means that Y is right for Z language is absolute nonsense. R is a statistical programming language that is C-like and
return is a function in R.