Skip to main content

Bug Tracker

Side navigation

#10874 closed bug (duplicate)

Opened November 23, 2011 01:51PM UTC

Closed November 23, 2011 02:24PM UTC

Last modified November 23, 2011 02:24PM UTC

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:
Blocked by: Blocking:
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.

Attachments (0)
Change History (2)

Changed November 23, 2011 02:24PM UTC by timmywil comment:1

resolution: → duplicate
status: newclosed

Changed November 23, 2011 02:24PM UTC by timmywil comment:2

Duplicate of #5571.