Skip to content
This repository has been archived by the owner on Apr 16, 2019. It is now read-only.

CANNOT set the falsy values through $.data(). #609

Closed
LeoYuan opened this issue Mar 10, 2014 · 0 comments
Closed

CANNOT set the falsy values through $.data(). #609

LeoYuan opened this issue Mar 10, 2014 · 0 comments

Comments

@LeoYuan
Copy link
Contributor

LeoYuan commented Mar 10, 2014

bug description

two bugs:

  1. if you want to set a falsy value(e.g. false, 0) through $.data() will never take effect, 'cause the if course inside which decide to set some value or not will never get executed.
  2. the $.data getter will accidently convert a number-like string to a number.

how to reproduce?

1.
$('body').data('key', true);    // output `true`
$('body').data('key', false);    // output `true`

2. 
$('body').data('anotherKey', '1');  // output 1

how to fix?

if (value) {  // wrong
if (value !== undefined && value !== null) {

what a shame, a pull request which created by me several months ago resulted in this error...^_^

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

No branches or pull requests

2 participants