Skip to content

Instantly share code, notes, and snippets.

@jameswomack
Created March 11, 2014 01:20
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 jameswomack/9477774 to your computer and use it in GitHub Desktop.
Save jameswomack/9477774 to your computer and use it in GitHub Desktop.
Getters|Setters & Private|Public Scope in JavaScript
function DepartmentStore(name, location) {
var define = Object.defineProperty.bind(undefined, this);
define('title', {
get: function () {
return name.concat(' ', location);
}
});
define('location', {
set: function (value) {
return location = value;
}
});
}
var atré = new DepartmentStore('Atré', '品川');
console.log(atré.title);
atré.location = '原宿';
console.log(atré.title);
console.log(atré.location);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment