Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User {
- constructor({ name, continent, email }) {
- this.setName(name);
- this.setEmail(email);
- this.setContinent(continent);
- }
- setName(name) {
- this.name = name;
- }
- setContinent(continent) {
- this.continent = continent;
- }
- setEmail(email) {
- this.email = email;
- }
- }
- class UserGPDRDecorator {
- constructor({ UserInstance, allowCookies = true }) {
- if (UserInstance.continent === "Europe") {
- UserInstance.setAllowCookies = this.setAllowCookies;
- UserInstance.deleteAllMyData = this.deleteAllMyData;
- UserInstance.setAllowCookies(allowCookies);
- }
- return UserInstance;
- }
- setAllowCookies(allowCookies) {
- this.allowCookies = allowCookies;
- }
- deleteAllMyData() {
- if (this.continent === "Europe") {
- delete this.name;
- delete this.continent;
- delete this.email;
- delete this.allowCookies;
- }
- }
- }
- const run = () => {
- const userRicardoInstance = new UserGPDRDecorator({
- UserInstance: new User({
- name: "Ricardo",
- continent: "Europe",
- email: "ricardo@ricardo.com",
- }),
- allowCookies: false,
- });
- console.log(userRicardoInstance);
- userRicardoInstance.deleteAllMyData();
- console.log(userRicardoInstance);
- const userRobInstance = new User({
- name: "Rob",
- continent: "America",
- email: "rob@rob.com",
- });
- console.log(userRobInstance);
- };
- run();
Add Comment
Please, Sign In to add comment