Last active
August 29, 2015 14:24
-
-
Save jaydson/f718d0c91cba46316830 to your computer and use it in GitHub Desktop.
ES7 Decorator test
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 Foo { | |
@returns(Number) | |
init() { | |
console.log('ccc'); | |
} | |
} | |
function returns(type) { | |
return (target, name, descriptor) => { | |
descriptor.value = function(val) { | |
if(val.constructor !== type) { | |
throw new Error('Invalid type'); | |
} | |
} | |
return descriptor; | |
} | |
} | |
var foo = new Foo(); | |
foo.init(34); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment