Skip to main content

Bug Tracker

Side navigation

#9511 closed bug (duplicate)

Opened June 03, 2011 07:55PM UTC

Closed June 03, 2011 07:58PM UTC

Last modified June 03, 2011 07:58PM UTC

trigger cannout distinguish undefined from numeric 0 when passing single arg

Reported by: dreizen@kupad.net 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

});

Attachments (0)
Change History (2)

Changed June 03, 2011 07:58PM UTC by rwaldron comment:1

component: unfiledevent
priority: undecidedlow
resolution: → duplicate
status: newclosed

Changed June 03, 2011 07:58PM UTC by rwaldron comment:2

Duplicate of #9285.