A Pen by Yerlin Matu on CodePen.
Created
May 12, 2019 21:10
-
-
Save YerlinMatu/ac9c1a120baf0146ba71ba86bd20a00d to your computer and use it in GitHub Desktop.
GaqLbP
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
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