Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#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:
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.

Change History (2)

comment:1 Changed 12 years ago by Timmy Willison

Resolution: duplicate
Status: newclosed

comment:2 Changed 12 years ago by Timmy Willison

Duplicate of #5571.

Note: See TracTickets for help on using tickets.