Skip to content

Instantly share code, notes, and snippets.

@snowmantw
Created December 8, 2015 14:56
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 snowmantw/f6ae1533f31bb820dbc5 to your computer and use it in GitHub Desktop.
Save snowmantw/f6ae1533f31bb820dbc5 to your computer and use it in GitHub Desktop.
Static decorator check.
function procedure(instance, method, description) {
//console.log(description)
description.value.__procedure = true;
var org = description.value;
if (instance.__procedureDefined) {
throw new Error('Already has one procedure');
}
instance.__procedureDefined = true;
description.value = function() {
console.log('>>>>> wrapped');
return org.apply(this, arguments)
}
}
class Clz{
@procedure
main() {
console.log('>>>> original');
return 3;
}
//@procedure
notmain() {
console.log('<<<< should not happen');
}
}
var c = new Clz();
c.main();
console.log(c.main.__procedure);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment