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

Add a check for unnecessary use of call? #650

Closed
chrisprice opened this issue Sep 14, 2012 · 3 comments
Closed

Add a check for unnecessary use of call? #650

chrisprice opened this issue Sep 14, 2012 · 3 comments

Comments

@chrisprice
Copy link

Given -

var a = {
b: function() {}
};

Should the following code not trigger a warning about the unnecessary use of call?

a.b.call(a);

(I think the above is exactly equivalent to - a.b();)

If so the check should probably be generalised to n arguments.

@valueof
Copy link
Member

valueof commented Sep 16, 2012

What is the reasoning behind this? Just overall code cleanliness or something bigger? If former, we'll make it possible to extend JSHint for such cases soon. If latter, please send a patch.

@valueof valueof closed this as completed Sep 16, 2012
@chrisprice
Copy link
Author

It was the former, I had just being reviewing some code and it stood out to me as a good candidate for a warning. a.b.call(a) suggests to me that the author has not fully understood when it is appropriate to use call.

I suppose the same check should also be applied for -

a.b.apply(a, [c...]) equivalent to a.b(c...)
a.b.apply(a) equivalent to a.b()
a.b.call(a, c...) equivalent to a.b(c...)
a.b.call(a) equivalent to a.b()

@chrisprice
Copy link
Author

FYI, JSLint now warns as I suggested -

http://tech.groups.yahoo.com/group/jslint_com/message/3004

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants