Bug Tracker

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#9511 closed bug (duplicate)

trigger cannout distinguish undefined from numeric 0 when passing single arg

Reported by: dreizen@… Owned by:
Priority: low Milestone: 1.next
Component: event Version: 1.6.1
Keywords: Cc:
Blocked by: Blocking:

Description

when passing an argument to trigger a custom event, if zero is passed, the custom event's parameter will be undefined.

trigger behaves properly when passing the single argument wrapped in an array

Here's a code example of the error:

trigger does not behave as expected. $("#foo").bind('bar',function(e,num){

if( typeof(num)==="undefined" ){

window.console.log("foobar: undefined");

}else{

window.console.log("foobar: "+num);

}

}); $("#foo").trigger('bar',1); alerts 1 $("#foo").trigger('bar'); alerts "undefined" as expected $("#foo").trigger('bar',0); YIKES! alerts "undefined"

below, just for comparison, is the function spoon which behaves as expected var spoon = function(num){

if( typeof(num)==="undefined" ){

window.console.log("working: undefined");

}else{

window.console.log("working: "+num);

}

}; spoon(1); alerts 1

spoon(); alerts "undefined" as expected spoon(0); alerts 0 as expected

});

Change History (2)

comment:1 Changed 8 years ago by Rick Waldron

Component: unfiledevent
Priority: undecidedlow
Resolution: duplicate
Status: newclosed

comment:2 Changed 8 years ago by Rick Waldron

Duplicate of #9285.

Note: See TracTickets for help on using tickets.