Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save szaranger/2ba6d71c55a21841671abb34d9523193 to your computer and use it in GitHub Desktop.
Save szaranger/2ba6d71c55a21841671abb34d9523193 to your computer and use it in GitHub Desktop.
export class Person {
@Emoji()
name = 'Sean';
}
// Property Decorator
function Emoji() {
return function(target: Object, key: string | symbol) {
let val = target[key];
const getter = () => {
return val;
};
const setter = (next) => {
console.log('updating name...');
val = `${next}`;
};
Object.defineProperty(target, key, {
get: getter,
set: setter,
enumerable: true,
configurable: true,
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment