arc-object
Advanced tools
Comparing version 1.2.1 to 1.3.0
15
index.js
@@ -225,2 +225,17 @@ "use strict"; | ||
static duckInstanceOf(_primary,_duck){ | ||
if(is(_primary) !== 'object' || is(_duck) !== 'object'){ | ||
return false; | ||
} | ||
var prop; | ||
for(prop in _primary){ | ||
if(_primary.hasOwnProperty(prop) && is(_primary[prop]) === 'function'){ | ||
if(is(_duck[prop]) !== 'function'){ | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
//Take dynamic arguments and check that they're initialized objects | ||
@@ -227,0 +242,0 @@ static check(){ |
{ | ||
"name": "arc-object", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "An object convenience subclass", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -169,2 +169,31 @@ # arc-object [![Build Status](https://travis-ci.org/anyuzer/arc-object.svg?branch=master)](https://travis-ci.org/anyuzer/arc-object) | ||
### ArcObject.duckInstanceOf(primary:Object,duck:Object) | ||
Compare two objects to see if the duck object has the same properties bound as functions as the primary object | ||
```js | ||
//Example class | ||
class Test{ | ||
getSomething(){} | ||
} | ||
//Two seperate instantiations | ||
var primary = new Test; | ||
primary.id = "one thing"; | ||
var duck = new Test; | ||
duck.id = "another thing"; | ||
//Comparison | ||
(primary == duck); //false | ||
(primary === duck); //false | ||
ArcObject.duckInstanceOf(primary,duck); //true | ||
//Change the interface on the primary, so the duck no longer matches | ||
primary.newFunc = function(){}; | ||
ArcObject.duckInstanceOf(primary,duck); //false | ||
//But reverse the order... | ||
ArcObject.duckInstanceOf(duck,primary); //true (because we are not comparing if the interfaces are identical, only if the secondary has the same interface as the primary) | ||
``` | ||
### ArcObject.check(...args) | ||
@@ -171,0 +200,0 @@ This is a static method that can be used to check whether or not an object chain has been instantiated. |
25635
15
531
232