Ticket #7266 (closed enhancement: invalid)
jQuery show and hide functions don't work properly when returned by ternary statements
| Reported by: | f.mardini@… | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | 1.5 |
| Component: | core | Version: | 1.4.3 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
In the test case I link to in this bug, I use a ternary statement to decide whether to run hide or show. However, if the condition for the ternary is a statement, the functions are not returned properly. This is demonstrated by using ternary statements to hide both 'Div X', 'Div Y' and 'Div Z'. However, although all the written ternary statements are supposed to be equivalent, the second one does not work.
This was tested on both Firefox and Chrome on mac.
Change History
comment:2 in reply to: ↑ 1 ; follow-up: ↓ 3 Changed 3 years ago by anonymous
The problem is that it works correctly when the condition is true, but when the condition is an expression, it doesn't work. Shouldn't the behavior be the same regardless of the type of the condition used?
Replying to caii:
not jquery bug , see:
m={a:"cmc",f:function(){alert(this.a)}}
m.f();/*cmc*/
n=function(){};
(1==1?m.f:n)()/*undefined*/
you lost the 'this' in show/hide function
comment:3 in reply to: ↑ 2 Changed 3 years ago by caii
Replying to anonymous:
The problem is that it works correctly when the condition is true, but when the condition is an expression, it doesn't work. Shouldn't the behavior be the same regardless of the type of the condition used?
Yes, when the condition is true it works in Firefox. Maybe it's Firefox's bug..
(true ? $("#x").hide : $("#x").show)(); Equivalent to ($("#x").hide)() in firefox so it works.
when the condition is an expression, the object return by the "?:" is a function as it under window,so the function can't executive for the 'this' in the function body are window.
sorry for my poor english :)
comment:5 Changed 3 years ago by jitter
Did you mean to link to http://jsfiddle.net/YMs5b/3/ ?
In Opera only DIV Z is hidden which makes sense as explained by caii
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

not jquery bug , see:
m={a:"cmc",f:function(){alert(this.a)}}
m.f();/*cmc*/
n=function(){};
(1==1?m.f:n)()/*undefined*/
you lost the 'this' in show/hide function