Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bbmoz/extend-decorator
Extend your objects using a decorator!
https://github.com/bbmoz/extend-decorator
annotation babel decorator dom es2016 es7 extend inject
Last synced: 5 days ago
JSON representation
Extend your objects using a decorator!
- Host: GitHub
- URL: https://github.com/bbmoz/extend-decorator
- Owner: bbmoz
- License: mit
- Created: 2017-04-04T01:17:42.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-01T15:32:05.000Z (almost 7 years ago)
- Last Synced: 2025-01-11T11:07:49.099Z (14 days ago)
- Topics: annotation, babel, decorator, dom, es2016, es7, extend, inject
- Language: JavaScript
- Homepage: https://git.io/vSK8c
- Size: 86.9 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Extend Decorator
[![npm version](https://badge.fury.io/js/extend-decorator.svg)](https://badge.fury.io/js/extend-decorator)
[![Build Status](https://travis-ci.org/bbmoz/extend-decorator.svg)](https://travis-ci.org/bbmoz/extend-decorator)> Extend using a decorator!
## Example
Given two classes *Hi* and *Boo*, extend *Hello*.
```javascript
// part 1a
class Hi {
sayHi () {
return 'hi'
}
}
export default Hi
``````javascript
// part 1b
class Boo {
sayBoo () {
return 'boo'
}
}
export default Boo
``````javascript
// part 2
import extend from 'extend-decorator'
import Hi from './Hi'
import Boo from './Boo'@extend(Hi)
class Hello {
constructor ($hello) {
$hello.innerHTML = this.sayHi() // hello
}
sayHi () {
return 'hello'
}
}@extend(Hi, Boo, true)
class HelloOverwrite {
constructor ($helloOverwrite) {
$helloOverwrite.innerHTML = `${this.sayHi()} and ${this.sayBoo()}` // hi and boo
}
sayHi () {
return 'hello'
}
}
```If the last argument for `@extend()` is a boolean true, overwrite matching methods. To extend with more objects, just pass them as additional arguments i.e. `@extend(A, B, C)`.