Skip to content

Check against null, as 0 is a falsy value.#24

Merged
hilios merged 1 commit intohilios:masterfrom
romanbsd:master
Dec 12, 2013
Merged

Check against null, as 0 is a falsy value.#24
hilios merged 1 commit intohilios:masterfrom
romanbsd:master

Conversation

@romanbsd
Copy link
Copy Markdown
Contributor

For the first countdown instance it returns 0, and it's a falsy value.

@hilios
Copy link
Copy Markdown
Owner

hilios commented Nov 26, 2013

Yeah, blame on me I didn't though on this :( much appreciated with this fix, the only comment that I have is to follow the Google JavaScript Guidelines and do a strict comparission !== null do that and will merge right away.

Thanks

@romanbsd
Copy link
Copy Markdown
Contributor Author

It's deliberately != because it can be undefined. So either have two strict conditions or this one.

@FagnerMartinsBrack
Copy link
Copy Markdown
Contributor

!== undefined would be better than considering another unrelated condition.
It is always wise to test such behavior.

@romanbsd
Copy link
Copy Markdown
Contributor Author

Then you'll need -

if (typeof instanceNumber !== 'undefined' && instanceNumber !== null)

I deliberately picked instanceNumber != null because it's shorter, and because I know what are the possible values here and I want javascript to cast the value.

@FagnerMartinsBrack
Copy link
Copy Markdown
Contributor

Where is the null from?

@FagnerMartinsBrack
Copy link
Copy Markdown
Contributor

I never fully worked in the code btw, this is the first time I see it. But as I can see from github view it is not setting null anywhere.

@romanbsd
Copy link
Copy Markdown
Contributor Author

yep, it does a delete. And delete is supposedly sets it to undefined. So it can be just: typeof instanceNumber !== 'undefined'

@FagnerMartinsBrack
Copy link
Copy Markdown
Contributor

I would go for instanceNumber !== undefined instead of add 11 unnecessary characters.
and this could be })(function($, undefined){ for minification ;D

@FagnerMartinsBrack
Copy link
Copy Markdown
Contributor

Not that I personally care

@romanbsd
Copy link
Copy Markdown
Contributor Author

if you want to save characters, then != null wins hands down :)

@FagnerMartinsBrack
Copy link
Copy Markdown
Contributor

null:

  • Cannot be minified
  • Add unnecessary implicit undefined check

undefined:

  • Can be minified by assigning to an undefined variable })(function($, undefined){
  • Does not make anything implicit

@FagnerMartinsBrack
Copy link
Copy Markdown
Contributor

})(function($, undefined){ will minify to })(function($, a){ and all occurrences will change from undefined to a

@romanbsd
Copy link
Copy Markdown
Contributor Author

heh, nice 👍

@hilios
Copy link
Copy Markdown
Owner

hilios commented Dec 12, 2013

Besides all the technical details involving this issue, for me the problem here is the linter configuration of the project.

This PR build is broken by the rules adopted, understand that the decision of following the Google Guidelines was to ensure a proper workflow for collaborations, like yours. As well isn't a good practice to merge a broken PR.

The solution for the idiosyncrasy is found at jQuery.data documentation, as the following explanation and example:

"[...] If no data at all was set on that element, undefined is returned."

alert( $( "body" ).data( "foo" ) ); // undefined
$( "body" ).data( "bar", "foobar" );
alert( $( "body" ).data( "bar" ) ); // foobar

In theory a simple instanceNumber !== undefined would solve both problems, as @FagnerMartinsBrack mentioned. That's the final word about this issue.

I don't want to loose track of the collaboration I will try to add a commit to this PR before merging, or if @romanbsd do it first it would be 👍

Thanks guys!

@romanbsd
Copy link
Copy Markdown
Contributor Author

yeah, go ahead, I don't mind :)

@hilios
Copy link
Copy Markdown
Owner

hilios commented Dec 12, 2013

I just added a proper testing to this issue. By the way this PR fixed bug #22.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants