Created
November 12, 2021 00:27
-
-
Save szaranger/2ba6d71c55a21841671abb34d9523193 to your computer and use it in GitHub Desktop.
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 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