Update: '0' evaluates to true.
Diogo
On Sat, Nov 29, 2008 at 10:45 PM, Diogo Baeder <[EMAIL PROTECTED]>wrote:
> Hi, William! :-)
>
> Can I make a code suggestion?:
>
> jQuery.isEmpty = function(mixedVar) {
> return (!mixedVar || !mixedVar.length || !mixedVar == '0');
> };
>
> I can't remember, though, if a String "0" evaluates to false, in a Boolean
> or conditional test, like PHP does... if it does, you can leave out the
> third test from the method return statement.
>
> Diogo
>
>
>
>
> On Sat, Nov 29, 2008 at 8:21 PM, John Resig <[EMAIL PROTECTED]> wrote:
>
>>
>> We have an isArray method in the latest nightlies (jQuery.isArray) but
>> unless we have a need for it in core we're not likely to add a method
>> like isEmpty.
>>
>> This would make for a perfectly acceptable plugin, though - thanks for
>> the suggestion!
>>
>> --John
>>
>>
>>
>> On Sat, Nov 29, 2008 at 10:18 AM, William Chang <[EMAIL PROTECTED]>
>> wrote:
>> >
>> > I would like to make a request (or proposal) to be included in the
>> > next version of jQuery: isEmpty() method to return true or false for
>> > condition statements. I'm not sure jQuery have something like this,
>> > but let me know if it exist or does not exist? Thanks!
>> >
>> > By the way, this is for jQuery Utilities: Object/Test Operation
>> >
>> > Here is my code I use to do isEmpty in JavaScript. Someone can make it
>> > better please for jQuery:
>> >
>> > // Is empty.
>> > function isEmpty(mixed_var) {return (mixed_var == undefined ||
>> > mixed_var === '' || mixed_var === 0 || mixed_var === '0' || mixed_var
>> > === null || mixed_var === false || (isArray(mixed_var) &&
>> > mixed_var.length === 0));}
>> > // Is array.
>> > function isArray(mixed_var) {return (mixed_var instanceof Array);}
>> >
>> > >
>> >
>>
>> >>
>>
>
>
> --
> Diogo Baeder
> http://www.diogobaeder.com.br
>
--
Diogo Baeder
http://www.diogobaeder.com.br
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---