Skip to content

Instantly share code, notes, and snippets.

@tdimnet
Created September 1, 2021 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tdimnet/f6010c8087cc9fb45ebc060fa36df57a to your computer and use it in GitHub Desktop.
Save tdimnet/f6010c8087cc9fb45ebc060fa36df57a to your computer and use it in GitHub Desktop.
class User {
constructor(firstName, lastName) {
this._firstName = firstName
this._lastName = lastName
}
sayHello() {
console.log(`L'utilisateur ${this._firstName} ${this._lastName} vous dit bonjour`)
}
}
const userWithUsername = (User, username) => {
User._username = username
User.sayHello = () => {
console.log(`${User._username} vous dit bonjour`)
}
return User
}
// L'utilisateur initialement
const OriginalUser = new User('Thomas', 'Dimnet')
OriginalUser.sayHello()
// L'utilisateur décoré
const DecoratedUser = userWithUsername(new User('Antoine', 'Dubois'), 'adubois')
DecoratedUser.sayHello()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment