Skip to content

Instantly share code, notes, and snippets.

@jaydson
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaydson/f718d0c91cba46316830 to your computer and use it in GitHub Desktop.
Save jaydson/f718d0c91cba46316830 to your computer and use it in GitHub Desktop.
ES7 Decorator test
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