Skip to content

Instantly share code, notes, and snippets.

@dualyticalchemy
Last active April 19, 2020 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dualyticalchemy/69a456735453d1e77e911acc5d027d4c to your computer and use it in GitHub Desktop.
Save dualyticalchemy/69a456735453d1e77e911acc5d027d4c to your computer and use it in GitHub Desktop.
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
@dualyticalchemy
Copy link
Author

Following the Single Responsibility Principle in SOLID, this shouldn’t be too big of a deal to maintain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment