Created
July 5, 2018 13:16
-
-
Save uinz/ba2e25107c42ad06fcc077f8d7481a36 to your computer and use it in GitHub Desktop.
Decorator babel 与 typescript 兼容
This file contains hidden or 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
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