Skip to content

Instantly share code, notes, and snippets.

@sonhanguyen
sonhanguyen / mixin_delegate_decorator.ts
Last active October 31, 2022 13:44
kotlin's style delegate in typescript
function delegateTo(prop: string) {
const { __proto__ } = this
Object.setPrototypeOf(this,
new Proxy({}, {
get: (target, name) => {
target = this[prop]
if (name === prop) return target
if (name in __proto__) return __proto__[name]
return target ? target[name] : undefined