Skip to content

Instantly share code, notes, and snippets.

@uinz
Created July 5, 2018 13:16
Show Gist options
  • Save uinz/ba2e25107c42ad06fcc077f8d7481a36 to your computer and use it in GitHub Desktop.
Save uinz/ba2e25107c42ad06fcc077f8d7481a36 to your computer and use it in GitHub Desktop.
Decorator babel 与 typescript 兼容
export function decoratorName() {
return function(target, prop, descriptor) {
if (descriptor) {
if (descriptor.value) {
// Typescript & @decorator method() { }
const originFunction = descriptor.value;
descriptor.value = function(...args) {
// @TODO:
return originFunction(...args);
};
}
// Babel only: @decorator method = () => {}
const { initializer } = descriptor;
descriptor.initializer = function() {
const originFunction = initializer.call(this);
return function(...args) {
return originFunction(...args);
};
};
}
return descriptor;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment