Skip to content
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

arguments.callee breaks inside generated closures #792

Closed
hen-x opened this issue Oct 23, 2010 · 6 comments
Closed

arguments.callee breaks inside generated closures #792

hen-x opened this issue Oct 23, 2010 · 6 comments

Comments

@hen-x
Copy link

hen-x commented Oct 23, 2010

This may come as a shock to absolutely no-one, but the value of arguments.callee changes inside generated closures:
test = ->
callees = arguments.callee for i from 0 to 0
callees[0]

test() is test # false      

One possible solution is to cache the value of arguments in the outer function, and then reinstate it in the closure, rather than passing it with apply():
var test;
test = function() {
var _result, callees, i, self;
var _arguments = arguments;
callees = (function() {
arguments = _arguments;
_result = [];
for (i = 0; i <= 0; i++) {
_result.push(arguments.callee);
}
return _result;
}).apply(this);
return callees[0];
};
test() === test; // true!
I don't know if arguments is made mutable by the spec, but this hack works in v8.

@zmthy
Copy link
Collaborator

zmthy commented Oct 23, 2010

Woah, I didn't realise Coffeescript compiled that way. The most appropriate solution would be to pass it through as an argument, using call instead of apply.
value = (function(arguments) { ... }).call(this, arguments);

@hen-x
Copy link
Author

hen-x commented Oct 23, 2010

@Tesco: Nice, and much cleaner! I'm amazed that having an argument a parameter named arguments actually overrides the default value.

@satyr
Copy link
Collaborator

satyr commented Oct 23, 2010

@zmthy
Copy link
Collaborator

zmthy commented Oct 23, 2010

Darn. Reverted, reopening.

@zmthy
Copy link
Collaborator

zmthy commented Oct 23, 2010

arguments gets the honour of pretty much being a keyword in strict mode. There's no way for us to fix this while taking that into consideration - just don't use the callee property, save the function to a variable instead (or implement the function keyword :D).

@satyr
Copy link
Collaborator

satyr commented Nov 15, 2010

FYI: satyr/coco#4

@jashkenas jashkenas added change and removed bug labels Nov 4, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants