Created
March 11, 2014 01:20
-
-
Save jameswomack/9477774 to your computer and use it in GitHub Desktop.
Getters|Setters & Private|Public Scope in JavaScript
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 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