You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you leave a space before a + operator but not after it, the compiler will interpret the + and the string behind it as being passed to as arguments to a function call. Here's an example:
test.coffee
test = "abc"
result = test+"def"
result = test + "def"
result = test+ "def"
result = test +"def"
test.js
// Generated by CoffeeScript 1.4.0
(function() {
var result, test;
test = "abc";
result = test + "def";
result = test + "def";
result = test + "def";
result = test(+"def");
}).call(this);
My first thought was that this must be just a consequence of CS optional parenthesis, but even when adding some parenthesis to try and separate the arguments, if the plus is adjacent to the string the result is the same:
test = "abc"
result = (test) +"def"
result = test +("def")
// Generated by CoffeeScript 1.4.0
(function() {
var result, test;
test = "abc";
result = test(+"def");
result = test(+"def");
}).call(this);
I think the fact that test +("def") is parsed into test(+"def"); seems especially odd.
Anyway, I wanted to share this since it really surprised me. Lastly, I realize this is not "typical" coding style so it's probably not encountered very often, however I discovered it because I accidentally left out the space after a + in some code today, and the result was TypeError: string is not a function, which was surprising.
Interested to hear whether this is considered a bug, and if not, why not. Thanks!
The text was updated successfully, but these errors were encountered:
If you leave a space before a
+
operator but not after it, the compiler will interpret the + and the string behind it as being passed to as arguments to a function call. Here's an example:test.coffee
test.js
My first thought was that this must be just a consequence of CS optional parenthesis, but even when adding some parenthesis to try and separate the arguments, if the plus is adjacent to the string the result is the same:
I think the fact that
test +("def")
is parsed intotest(+"def");
seems especially odd.Anyway, I wanted to share this since it really surprised me. Lastly, I realize this is not "typical" coding style so it's probably not encountered very often, however I discovered it because I accidentally left out the space after a
+
in some code today, and the result wasTypeError: string is not a function
, which was surprising.Interested to hear whether this is considered a bug, and if not, why not. Thanks!
The text was updated successfully, but these errors were encountered: