#9511 closed bug (duplicate)
trigger cannout distinguish undefined from numeric 0 when passing single arg
Reported by: | 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 12 years ago by
Component: | unfiled → event |
---|---|
Priority: | undecided → low |
Resolution: | → duplicate |
Status: | new → closed |
Duplicate of #9285.