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

"'hasOwnProperty' is a really bad name" #770

Closed
jashkenas opened this Issue Dec 11, 2012 · 5 comments

Comments

Projects
None yet
3 participants
@jashkenas
Copy link

jashkenas commented Dec 11, 2012

I was curious why JSHint has an error for:

'hasOwnProperty' is a really bad name

When you're writing code like this:

var hasOwnProperty = {}.hasOwnProperty;

... unless it's a leftover bug from the JSLint port:

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

Is it something that can be fixed in an update? Or is there a better reason?

@ghost ghost assigned valueof Dec 11, 2012

@valueof

This comment has been minimized.

Copy link
Member

valueof commented Dec 11, 2012

Yeah, that looks like a bug. We should warn about hasOwnProperty only if someone defines a new property/method with such name. I'll make sure it's fixed before the next release. Thanks!

@valueof valueof closed this in fbb9fd3 Dec 16, 2012

@szarouski

This comment has been minimized.

Copy link

szarouski commented Feb 28, 2013

Hi, is there a way to suppress this warning? I'm using localstorage fallback from https://developer.mozilla.org/en-US/docs/DOM/Storage#localStorage (at the bottom of that section) which overwrites hasOwnProperty method.

@valueof

This comment has been minimized.

Copy link
Member

valueof commented Feb 28, 2013

You can use /* jshint -W001 */

@szarouski

This comment has been minimized.

Copy link

szarouski commented Mar 3, 2013

I see. This is not scoped suppression, right? Also is there a way to turn warning back after /* jshint -W001 */?
Thank you.

@valueof

This comment has been minimized.

Copy link
Member

valueof commented Mar 3, 2013

It is function scoped.

jugglinmike added a commit to jugglinmike/jshint that referenced this issue Oct 21, 2014

Changed how hasOwnProperty warning behaves.
We don't need to warn about 'var hasOwnProperty = ...' and such so
now we only warn about the following cases:

	var obj = { hasOwnProperty: ... };
	obj.hasOwnProperty = ...;
	obj['hasOwnProperty'] = ...;

Closes jshintGH-770.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment