New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reserved word #82
Comments
I'm not opposed to this if we can gather data on people actually experiencing it as a problem. There are scant few cases when someone would ever want to import just one method on the module, so I'm not really convinced that hypothetical concern is going to be people's lived experience. I did some research and edge case testing when I renamed |
Yeah, the only real time I see this becoming a problem is with destructuring. I agree that most people won't grab just one method, but I do see myself, at least, doing something like: const {
func,
when,
verify,
matchers,
reset
} = require('test-double');
const fetch = func();
when(fetch(42)).thenReturn('Jane User');
fetch(42);
verify(fetch(matchers.isA(Number));
assert(explain(fetch).callCount, 1);
reset(); I personally like the readability of just As a second, less legitimate reason, |
How would you feel about simply adding func as an alias?
|
Yeah that sounds like a pretty good idea to me. On Mar 26, 2016, 20:09 -0400, Justin Searlsnotifications@github.com, wrote:
|
function
is a reserved word. I think it would be prudent to deprecatetd.function()
in favor of some other method name, perhapstd.func()
.The way the source is currently written, everything is actually valid.
function
is being used as anIdentifierName
, which has no problem with reserved words:However if someone were to do something like this, they'd get a syntax error:
I feel like the above will become a fairly common use case, so by changing the method name to something that can be destructured into an
Identifier
without a reserved word clash would save some headaches:Of course, if someone wanted to destructure with the current name they could do it:
But I feel like that is forcing people into doing something for the sake of lexical compatibility instead of expressiveness, which is, I think, the use case for destructed re-assignment.
Anyways, this is just a suggestion. I understand it could introduce some backwards compatibility problems.
The text was updated successfully, but these errors were encountered: