Skip to main content

Bug Tracker

Side navigation

#6385 closed bug (wontfix)

Opened April 01, 2010 03:18PM UTC

Closed October 14, 2010 03:39AM UTC

Last modified October 14, 2010 01:02PM UTC

getOrSet('value', undefined) should be interpreted as an attempt to set the value, rather than get it.

Reported by: mattlunn Owned by:
Priority: low Milestone: 1.4.3
Component: core Version: 1.4.2
Keywords: attributes value Cc:
Blocked by: Blocking:
Description

For methods such as val, html and attr, if the value parameter is undefined the call is interpreted as a get action rather than a set, and the jQuery chain is broken.

As a value for value was provided (shame it was undefined), I would expect jQuery to treat the action as a set.

See http://www.jsfiddle.net/3CAta/ as an example.

Regards,

Matt

Attachments (0)
Change History (2)

Changed October 14, 2010 03:39AM UTC by addyosmani comment:1

keywords: → attributes value
priority: → low
resolution: → wontfix
status: newclosed

I believe the reason for this fallback is that:

1. If a valid value previously existed, rather than undefined being set in it's place (what would undefined display as? empty string? null? undefined?) the previous value is instead still visible/accessible as a clean fallback.

2. Developer's are able to check for undefined values prior to setting them as the value of any attribute using less than a line of code. By not setting some default value for undefined in this case, we leave it open to you to sanitize the data in the way you see best fit (for example, as I mentioned above, you could decide whether a value of undefined resulted in an empty string, saying 'invalid entry' and so on).

Closing as I believe the present behavior offers more advantages than disadvantages.

Changed October 14, 2010 01:02PM UTC by dmethvin comment:2

This behavior has changed in 1.4.3 though, most setters no longer treat the setter

.method(undefined)
the same as a getter
.method()
although that obviously has its own tradeoffs since we have to decide what setting something to undefined does.

See #4388 and #4130; if we've missed some then open a specific ticket and reference those two.