Last active
April 19, 2020 14:51
-
-
Save dualyticalchemy/69a456735453d1e77e911acc5d027d4c to your computer and use it in GitHub Desktop.
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
function _displayModel (_private) { | |
console.log(_private.model); | |
} | |
function bind (that, func) { | |
return function(private) { | |
return func.bind(that, private); | |
}; | |
} | |
class Car { | |
constructor (model) { | |
this._private = { | |
model: model | |
}; | |
return { | |
displayModel: bind(this, _displayModel)(this._private) | |
}; | |
} | |
} | |
const car = new Car('CX-9'); | |
car.displayModel(); | |
console.log(car.displayModel.toString()); // prints function () { [native code] } | |
console.log(car._private) // undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Following the Single Responsibility Principle in SOLID, this shouldn’t be too big of a deal to maintain.