Skip to content

Instantly share code, notes, and snippets.

@colus001
Last active December 12, 2019 07:10
Show Gist options
  • Save colus001/bc9458fc45c5012803a06f6bcd4eff6a to your computer and use it in GitHub Desktop.
Save colus001/bc9458fc45c5012803a06f6bcd4eff6a to your computer and use it in GitHub Desktop.
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