Skip to content

Instantly share code, notes, and snippets.

@tatat
Created September 27, 2018 07:43
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 tatat/de869bbe4a815802ffbeb959e9cfaf62 to your computer and use it in GitHub Desktop.
Save tatat/de869bbe4a815802ffbeb959e9cfaf62 to your computer and use it in GitHub Desktop.
function FuckingPredeterminedMethodName(fuckinName: string) {
return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
target.__fuckingPredeterminedMethodNameCalled__ = target.__fuckingPredeterminedMethodNameCalled__ || {}
target.__fuckingPredeterminedMethodNameCalled__[fuckinName] = 0
target[fuckinName] = function() {
if (++ target.__fuckingPredeterminedMethodNameCalled__[fuckinName] > 3) {
throw new Error('Stop it!')
} else {
console.warn(`Do not call me ${ fuckinName }.`)
return target[propertyKey].apply(this, arguments)
}
};
};
}
class U {
@FuckingPredeterminedMethodName('inu')
neko(): U {
console.log('hai.')
return this
}
}
interface U {
inu(): U
}
new U().inu().inu().inu().neko().inu()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment