Bug Tracker

Modify

Ticket #10874 (closed bug: duplicate)

Opened 19 months ago

Last modified 19 months ago

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

comment:1 Changed 19 months ago by timmywil

  • Status changed from new to closed
  • Resolution set to duplicate

comment:2 Changed 19 months ago by timmywil

Duplicate of #5571.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.