I am just learning CoffeeScript, and I'm trying to do something that I would normally do in plain JavaScript.
Here is what I tried to do:
initializeWebGL = (canvas) ->
gl = canvas.getContext "webgl" or canvas.getContext "experimental-webgl"
Which compiles what I expect:
var initializeWebGL;
initializeWebGL = function(canvas) {
var gl;
return gl = canvas.getContext("webgl" || canvas.getContext("experimental-webgl"));
};
To get what I really want, I need to enclose the arguments getContextin parentheses:
initializeWebGL = (canvas) ->
gl = canvas.getContext("webgl") or canvas.getContext("experimental-webgl")
Which creates what I want:
var initializeWebGL;
initializeWebGL = function(canvas) {
var gl;
return gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
};
Is there a better way to do what I'm trying to achieve than just adding parentheses around function calls, as in the second example?
source
share