Last active
December 12, 2019 07:10
-
-
Save colus001/bc9458fc45c5012803a06f6bcd4eff6a to your computer and use it in GitHub Desktop.
This file contains 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
interface State { | |
position: number; | |
} | |
function createDog() { | |
const state: State = { | |
position: 0, | |
}; | |
return { | |
...voice(), | |
...barker(), | |
...voice(), | |
...walker(state), | |
}; | |
} | |
function voice() { | |
return { | |
voice(x: string) { | |
console.log(x); | |
}, | |
}; | |
} | |
function barker(this: typeof voice) { | |
return { | |
bark(x: string) { | |
this.voice(x); | |
}, | |
}; | |
} | |
function walker(state: State) { | |
return { | |
walk(step: number) { | |
state.position += step; | |
}, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment