Skip to content
This repository

Add a check for unnecessary use of call? #650

Closed
chrisprice opened this Issue · 3 comments

2 participants

Chris Price Anton Kovalyov
Chris Price

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.

Anton Kovalyov
Owner

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.

Anton Kovalyov valueof closed this
Chris Price

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.