Equivalent of jQuery's isEmptyObject()
The group you are posting to is a
Usenet group . Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
From:
Blackbird <cbram... @gmail.com>
Date: Sun, 11 Nov 2012 15:01:41 -0800 (PST)
Local: Sun, Nov 11 2012 6:01 pm
Subject: Equivalent of jQuery's isEmptyObject()
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Arian Stolwijk <stolwijk.ar... @gmail.com>
Date: Mon, 12 Nov 2012 00:09:46 +0100
Local: Sun, Nov 11 2012 6:09 pm
Subject: Re: [Moo] Equivalent of jQuery's isEmptyObject()
You could use:
Object.every({}, function(){ return false }) // true
Object.every({a: 1}, function(){ return false }) // false
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Arian Stolwijk <stolwijk.ar... @gmail.com>
Date: Mon, 12 Nov 2012 00:12:21 +0100
Local: Sun, Nov 11 2012 6:12 pm
Subject: Re: [Moo] Equivalent of jQuery's isEmptyObject()
Or with simple JS:
var empty = true;
for (var k in object){ empty = false; break; }
On Mon, Nov 12, 2012 at 12:09 AM, Arian Stolwijk
<stolwijk.ar... @gmail.com>wrote:
> You could use:
> Object.every({}, function(){ return false }) // true
> Object.every({a: 1}, function(){ return false }) // false
> On Mon, Nov 12, 2012 at 12:01 AM, Blackbird <cbram... @gmail.com> wrote:
>> Hi,
>> Does Mootools have an equivalent to jQuery's isEmptyObject() function?
>> http://api.jquery.com/jQuery.isEmptyObject
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Blackbird <cbram... @gmail.com>
Date: Sun, 11 Nov 2012 15:26:57 -0800 (PST)
Local: Sun, Nov 11 2012 6:26 pm
Subject: Re: [Moo] Equivalent of jQuery's isEmptyObject()
Thanks for the reply. I think I will go for either of those JS solutions, found on Stackoverflow:
function isEmpty(obj) { for(var prop in obj) { if(obj.hasOwnProperty(prop)) return false; }
return true;}
Or for ECMAScript 5 compatible browsers: Object.keys( obj ).length === 0
I think jQuery's function is useful, and would be welcome in Mootools.
On Monday, November 12, 2012 12:12:43 AM UTC+1, Arian Stolwijk wrote:
> Or with simple JS:
> var empty = true; > for (var k in object){ empty = false; break; }
> On Mon, Nov 12, 2012 at 12:09 AM, Arian Stolwijk <stolwij... @gmail.com<javascript:> > > wrote:
>> You could use:
>> Object.every({}, function(){ return false }) // true >> Object.every({a: 1}, function(){ return false }) // false
>> On Mon, Nov 12, 2012 at 12:01 AM, Blackbird <cbra... @gmail.com<javascript:> >> > wrote:
>>> Hi,
>>> Does Mootools have an equivalent to jQuery's isEmptyObject() function? >>> http://api.jquery.com/jQuery.isEmptyObject
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Sanford Whiteman <sa... @figureone.com>
Date: Sun, 11 Nov 2012 21:27:36 -0500
Local: Sun, Nov 11 2012 9:27 pm
Subject: Re: [Moo] Equivalent of jQuery's isEmptyObject()
> Thanks for the reply. I think I will go for either of those JS solutions,
> found on Stackoverflow:
> function isEmpty(obj) {
> for(var prop in obj) {
> if(obj.hasOwnProperty(prop))
> return false;
> }
> return true;}
A solution using hasOwnProp, while it may seem most complete, does
make its own assumption about emptiness. This may make it compatible
with jQuery but it's not the only definition: deliberately inherited
properties may suffice to make an object non-empty depending on your
ecosystem. YMMV....
-- Sandy
You must
Sign in before you can post messages.
You do not have the permission required to post.