https://github.com/gocardless/object-factory.js
A thin model inheritance layer. Built for Angular.js.
https://github.com/gocardless/object-factory.js
Last synced: 3 months ago
JSON representation
A thin model inheritance layer. Built for Angular.js.
- Host: GitHub
- URL: https://github.com/gocardless/object-factory.js
- Owner: gocardless
- License: mit
- Created: 2013-08-05T21:38:49.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2013-09-09T18:33:37.000Z (over 11 years ago)
- Last Synced: 2025-01-14T08:52:53.271Z (5 months ago)
- Language: JavaScript
- Homepage:
- Size: 219 KB
- Stars: 0
- Watchers: 110
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# ObjectFactory.js

A thin object inheritance layer. Built for Angular.js.
Exposes `create` method which calls `Object.create(this)` using redefine.js
and sets passed in attributes as enumerable properties.Mixes in eddy.js event methods.
Eddy methods: `on`, `once`, `off`, `trigger`, `boundTo`, `emit`
Requirements:
- ES5 Browser
- redefine.js: https://github.com/WebReflection/redefine
- eddy: https://github.com/WebReflection/eddy (modified to not extend all objects)## Angular.js $http adapter
Coming soon...
## Base object
```javascript
var Customer = ObjectFactory.create({
consts: Object.freeze({
AUTHORIZED_STATUS: 'authorised',
}),
isAuthorized: function isAuthorized() {
return this.status === this.consts.AUTHORIZED_STATUS;
}
});
```## Instance creation
```javascript
var customer = Customer.create({
name: 'Frank',
status: 'authorised'
});// Access object methods
customer.isAuthorized(); // true
```### Meta instance creation...
```javascript
var customersSon = customer.create({
name: 'Frank Jr.'
});
customersSon.status; // 'authorised'
```## Event mixin
Uses @WebReflectios eddy.js: https://github.com/WebReflection/eddy
```javascript
var Box = ObjectFactory.create();
Box.on('event', function(event) {
console.log(event.called);
}).trigger('event', { called: 'called' });
```## Copyright and license
Copyright 2013 GoCardless, Inc under the MIT license.