prototypes
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -44,2 +44,14 @@ 'use strict'; | ||
newObject.hasProperties = function() | ||
{ | ||
for (var key in this) | ||
{ | ||
if (this.hasOwnProperty(key)) | ||
{ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
/** | ||
@@ -46,0 +58,0 @@ * Get a function to filter keys. |
{ | ||
"name": "prototypes", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "Some common prototypes for node.js: string.startsWith(), object.countProperties() and more. Facilities for functional programming with objects: object.forEach(), object.filter(). Functions are added safely using Object.defineProperty().", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/alexfernandez/prototypes", |
@@ -281,2 +281,26 @@ [![Build Status](https://secure.travis-ci.org/alexfernandez/prototypes.png)](http://travis-ci.org/alexfernandez/prototypes) | ||
### object.hasProperties() | ||
Simply find out if the object has any properties at all. | ||
Most of the time you just want to see if you have an empty object; | ||
this function is for you! | ||
Faster than counting all properties. | ||
Does not count inherited properties: uses hasOwnProperty(). | ||
Example: | ||
```js | ||
{hello: 'a'}.hasProperties(); | ||
//=> true | ||
{}.hasProperties(); | ||
//=> false | ||
``` | ||
Common usage: | ||
```js | ||
var params = JSON.parse(string); | ||
if (!params.hasProperties()) return; | ||
``` | ||
### object.overwriteWith(overwriter) | ||
@@ -283,0 +307,0 @@ |
30969
731
629