Created
October 10, 2015 18:37
-
-
Save BadBastion/2a459759a6806ca6d3ef to your computer and use it in GitHub Desktop.
Javascript getters and setters
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
var person = {sutff:"stuff"}; | |
Object.defineProperty(person, 'fullName', { | |
get: function() { | |
return firstName + ' ' + lastName; | |
}, | |
set: function(name) { | |
var words = name.split(' '); | |
this.firstName = words[0] || ''; | |
this.lastName = words[1] || ''; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment