Skip to content

Attributes: Fixed Coding Convention#3221

Closed
mixed wants to merge 1 commit intojquery:masterfrom
mixed:fixedTypeCheck2
Closed

Attributes: Fixed Coding Convention#3221
mixed wants to merge 1 commit intojquery:masterfrom
mixed:fixedTypeCheck2

Conversation

@mixed
Copy link
Copy Markdown
Contributor

@mixed mixed commented Jul 6, 2016

Summary

Properties should check undefined using object.prop === undefined.
https://contribute.jquery.org/style-guide/js/#type-checks

Checklist

Mark an [x] for completed items, if you're not sure leave them unchecked and we can assist.

Thanks! Bots and humans will be around shortly to check it out.

Properties should check undefined using `object.prop === undefined`.
https://contribute.jquery.org/style-guide/js/#type-checks
Comment thread src/attributes/attr.js

// Fallback to prop when attributes are not supported
if ( typeof elem.getAttribute === "undefined" ) {
if ( elem.getAttribute === undefined ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was intentional, but probably not needed anymore. @jquery/core Does anyone remember at what point IE stopped automatically invoking the method on mere reference?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either IE7 or IE8, so we should be in the clear.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was only certain properties in IE8, but I think we're safe now. We could probably do just...

if ( !elem.getAttribute ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it violate our code style?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, pretty sure we added tests for that, so if they pass we should definitely be in the clear

Copy link
Copy Markdown
Member

@timmywil timmywil Jul 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it violate our code style?

Sure, we can change it, tho. Those styles were decided based on what we needed to do for old IE.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you wanna? :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do, as long as we no longer have to use typeof.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To conclude: we still need typeof in some places for all IE versions as it still has the auto-invoking problem for some host objects: https://github.com/jquery/jquery/blob/e4fd41f/src/manipulation/getAll.js#L10

@markelog
Copy link
Copy Markdown
Member

markelog commented Jul 8, 2016

Added correspondent ticket for eslint config - jquery/eslint-config-jquery#5

@timmywil
Copy link
Copy Markdown
Member

Since we should make a sweep across the whole repo, and the check will probably not look like the one proposed here, I'll close this PR. Added to Roadmap.

@timmywil timmywil closed this Jul 13, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

7 participants