- clone
npm install
npm run go
Last active
March 11, 2016 10:16
-
-
Save husa/92625b27a3f114910159 to your computer and use it in GitHub Desktop.
ES7 decorators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"presets": ["es2015"], | |
"plugins": ["transform-decorators-legacy"] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Product { | |
@insurance | |
@tax(15) | |
cost () { | |
return 100; | |
} | |
} | |
let p = new Product() | |
console.log(p.cost()) // 165 | |
function insurance (target, key, descriptor) { | |
const price = descriptor.value(); | |
descriptor.value = () => price + 50; | |
return descriptor; | |
} | |
function tax (taxValue) { | |
return (target, key, descriptor) => { | |
const price = descriptor.value(); | |
descriptor.value = () => { | |
return (1 + taxValue / 100) * price | |
} | |
return descriptor; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "Babel-es2016-decorators", | |
"version": "1.0.0", | |
"description": "", | |
"main": "main.js", | |
"scripts": { | |
"go": "babel main.js | node" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"babel-cli": "^6.6.5", | |
"babel-core": "^6.7.2", | |
"babel-plugin-transform-decorators-legacy": "^1.3.4", | |
"babel-preset-es2015": "^6.6.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment