Ticket #10874 (closed bug: duplicate)
Undefined second parameters triggers getter instead of setter
| Reported by: | MrMamen | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | None |
| Component: | unfiled | Version: | 1.7.1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
Consider the following function:
function f(bar) {
var $div = $("<div />").data("foo", bar);
}
The $div variable should be the DOM object, since data with two parameters is a setter and returns itself. However if the function f is called without a parameter, "bar" is undefined, and data triggers get method, and returns undefined instead.
See jsFiddle here: http://jsfiddle.net/mrmamen/3Xqk7/
This applies not only to data, but also to attr, css, and probably most if not all of jQuerys methods with have setter and getter.
Note: You can detect the difference between these: test(foo) and test(foo, undefined) be checking arguments.length.
Change History
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
