Skip to content

Instantly share code, notes, and snippets.

@YerlinMatu
Created May 12, 2019 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YerlinMatu/ac9c1a120baf0146ba71ba86bd20a00d to your computer and use it in GitHub Desktop.
Save YerlinMatu/ac9c1a120baf0146ba71ba86bd20a00d to your computer and use it in GitHub Desktop.
GaqLbP
class Context {
constructor(strategy) {
this.strategy = strategy;
}
doAction() {
this.strategy.doActionStrategy();
}
}
const strategy1 = {
doActionStrategy: function () {
console.log('Hellold');
}
};
const strategy2 = {
doActionStrategy: function () {
console.log('Byeld');
}
};
const obj1 = new Context(strategy1);
const obj2 = new Context(strategy2);
obj1.doAction(); // 'Hellor World'
obj2.doAction(); // 'Bye World'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment