O_o
wtf, I thought that valueOf was ignored for those kind of bools.

Taking another look, !! doesn't even run valueOf as I thought.

My comment was on the > operator, and your comment about what jquery 
shows up as in firebug if used.

jQuery.fn.valueOf = function(hint){
    if ( hint === "number" )
       return this.length;
    return this.get(); // on a second note, it would be nice to use a 
toArray() instead.
};

~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name]

John Resig wrote:
> Nope.
>
> var obj = { valueOf: function(){ return 0; } };
> !!obj
> >> true
>
> obj.valueOf().constructor
> >> Number()
>
> It looks like it's returning the number as Number(0) rather than in 
> its primitive form.
>
> --John
>
>
> On Thu, Jul 23, 2009 at 5:49 PM, Daniel Friesen 
> <nadir.seen.f...@gmail.com <mailto:nadir.seen.f...@gmail.com>> wrote:
>
>
>     John Resig wrote:
>     > I'm hesitant to add that (I've definitely thought about it, in the
>     > past) because .valueOf() doesn't cover all comparison cases.
>     >
>     > obj > obj2 works (as you noted)
>     > but if ( obj ) {} doesn't (it always returns true)
>     >
>     > Additionally, in Firebug, the result shows up as a number rather
>     than
>     > something more useful (like a list of elements).
>     What about type hinting?
>
>     ~Daniel Friesen (Dantman, Nadir-Seen-Fire)
>     [http://daniel.friesen.name]
>
>     > --John
>     >
>     >
>     > On Thu, Jul 23, 2009 at 2:06 PM, James Padolsey
>     > <jamespadol...@googlemail.com
>     <mailto:jamespadol...@googlemail.com>
>     <mailto:jamespadol...@googlemail.com
>     <mailto:jamespadol...@googlemail.com>>>
>     > wrote:
>     >
>     >
>     >     Just a thought; this would be quite useful IMO:
>     >
>     >     var paras = $('p'), uls = $('ul');
>     >     if (paras > uls) {
>     >        // ...
>     >     }
>     >
>     >     I know it's not quite as readable (or as semantic) as:
>     >
>     >     if (paras.length > uls.length) {
>     >        // ...
>     >     }
>     >
>     >     but still, it's one of those things that may as well be
>     added, just
>     >     for the few situations where it may be useful.
>     >
>     >     jQuery.fn.valueOf = function(){return this.length;};
>     >
>     >     Unless it's got some other valid use (with jQuery)...?
>     >
>     >
>     >
>     > >
>
>
>
>
> >

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to