Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryanve/blood
JavaScript object life
https://github.com/ryanve/blood
extend inherit inheritance javascript object objects
Last synced: about 1 month ago
JSON representation
JavaScript object life
- Host: GitHub
- URL: https://github.com/ryanve/blood
- Owner: ryanve
- License: mit
- Created: 2013-02-14T06:21:26.000Z (over 11 years ago)
- Default Branch: gh-pages
- Last Pushed: 2017-02-25T14:51:10.000Z (over 7 years ago)
- Last Synced: 2024-10-02T08:08:27.413Z (about 1 month ago)
- Topics: extend, inherit, inheritance, javascript, object, objects
- Language: JavaScript
- Homepage: http://ryanve.github.io/blood
- Size: 77.1 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# blood
#### JavaScript object life```
npm install blood --save
```## API
### Creation
- `blood.child(parent)` create object that inherits `parent` (emulates `Object.create`)
- `blood.create(parent)` alias for `blood.child(parent)`
- `blood.orphan()` emulates `Object.create(null)`
- `blood.twin(object)` [create twin object](http://stackoverflow.com/q/16594717/770127)
- `blood.combine(keys, values)` create object from corresponding keys and values arrays
- `blood.pair(pairs)` create object from pairs
- `blood.invert(object)` create new object by inverting keys and values### Mutation
- `blood.assign(to, ...from)` emulates ES6 `Object.assign`
- `blood.adopt(...from)` assign to `this`
- `blood.foster(child, parent)` force child to have a new parent (ES6+)### Reflection
- `blood.has(object, key)` test if `object` *owns* `key`
- `blood.parent(object)` emulates `Object.getPrototypeOf`
- `blood.parents(object)` get array of parents (up the prototype chain)
- `blood.chain(object)` equals `[object].concat(blood.parents(object))`
- `blood.keys(object)` emulates `Object.keys`
- `blood.names(object)` emulates `Object.getOwnPropertyNames`
- `blood.values(object)` get array of own enumerable values
- `blood.methods(object)` get array of own enumerable functions
- `blood.enums(object)` get array of all enumerable values
- `blood.pairs(object)` get array of `[key, value]` pairs## Developers
```
npm install
npm test
```## Compatibility
Works in Node.js and modern browsers (ES5+ except where noted ES6+)## Fund
[Fund opensource development](https://gratipay.com/~ryanve/) =)## Playground
[Try `blood` in your browser](http://ryanve.github.io/blood/)