I'm an old PHP developer and I like traits.
I have to interact with a bank, the class in Bank that does login and add the traits to get and commit requests.
trait GetRequest { public function getRequest() { ... } } trait CommitRequest { public function commitRequest($data) { ... } } class Bank { use GetRequest; use CommitRequest; public function login() { ... } }
So I can split class traits in different parts.
I had to work on a Javascript project.
Ahhhh!!! The traits does not exists, what can I do?
Use the mixin
class Bank { login() { ... } } let GetRequest = { getRequest() { ... } } let CommitRequest { commitRequest($data) { ... } } Object.assign(Bank.prototype, GetRequest); Object.assign(Bank.prototype, CommitRequest);
Top comments (0)