Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jcblw/js-decorators
a experiment with making js decorators using function mutation
https://github.com/jcblw/js-decorators
Last synced: 16 days ago
JSON representation
a experiment with making js decorators using function mutation
- Host: GitHub
- URL: https://github.com/jcblw/js-decorators
- Owner: jcblw
- Created: 2013-11-10T07:01:24.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2017-05-12T14:06:19.000Z (over 7 years ago)
- Last Synced: 2024-10-11T14:39:04.800Z (about 1 month ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### JS Decorators
Using function mutation. `Warning` this is just an experiment. The performance of this code is probably terrible and might have weird effects in differnt situations. You can find the file in
```
src / index.js
```it exposed the Decorate constructor... see below for examples or visit
```
test / runTest.html
```#### The Idea
Have JS Decorators similair to python ones, and allow for variable manipulation and a shared private scope between decorators and primary function.
#### Samples
all arguments passed into a decorated function should be mutatable and should reflect that in the primary fn.
eg.
```javascript
function decor ( a, b ) {
a = a + b;
}function primary ( a, b ) {
return a;
}primary = new Decorate( primary, decor );
primary( 1, 2 ); // 3
```decorators can cancel out fn before it hits the primary fn
```javascript
function decor ( ) {
return 'im return from a decorator';
}function primary () {
return 'im returning the primary stuff'
}primary = new Decorate( primary, decor );
primary( ); // 'im return from a decorator'
```variables can be passed from decorator to primary function.
```javascript
function decor ( ) {
var c = true;
}function primary ( ) {
if ( c ) {
return "C is defined"
}
}primary = new Decorate( primary, decor );
primary( ); // 'C is defined'
```