Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "delega", | ||
"description": "Concise creation of delegated methods for your classes/objects", | ||
"version": "0.1.0", | ||
"description": "Concise creation of delegate methods for your classes/objects", | ||
"version": "0.1.1", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Mario Casciaro" |
# Synopsis | ||
Concise creation of delegated methods for your classes/objects | ||
Concise creation of delegate methods for your classes/objects | ||
@@ -14,8 +14,42 @@ [![NPM](https://nodei.co/npm/delega.png?downloads=true)](https://nodei.co/npm/delega/) | ||
## Usage | ||
__For objects__ | ||
```javascript | ||
var objA = { | ||
foo: function() { | ||
return "a"; | ||
}, | ||
foo2: function() { | ||
return "b"; | ||
} | ||
}; | ||
var objB = {}; | ||
delega.delegateToObject(objB, objA, ['foo','foo2']); | ||
expect(objB.foo()).to.be.equal("a"); | ||
expect(objB.foo2()).to.be.equal("b"); | ||
``` | ||
__For classes__ | ||
```javascript | ||
...todo | ||
var objA = { | ||
foo: function() { | ||
return "a"; | ||
}, | ||
foo2: function() { | ||
return "b"; | ||
} | ||
}; | ||
var clazzB = function() { | ||
this.a = objA; | ||
}; | ||
delega.delegateToProperty(objB, 'a', ['foo', 'foo2']); | ||
expect(new clazzB().foo()).to.be.equal("a"); | ||
expect(new clazzB().foo2()).to.be.equal("b"); | ||
``` | ||
----- | ||
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/mariocasciaro/delega/trend.png)](https://bitdeli.com/free "Bitdeli Badge") |
6148
54