Skip to content

Instantly share code, notes, and snippets.

@marcelaraujo
Created April 14, 2014 01:50
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 marcelaraujo/10610355 to your computer and use it in GitHub Desktop.
Save marcelaraujo/10610355 to your computer and use it in GitHub Desktop.
Object es5
var person = {};
Object.defineProperty(person, 'firstName', {
get: function() { return firstName; },
set: function(newName) { firstName = newName; },
enumerable: true
});
Object.defineProperty(person, 'lastName', {
get: function() { return lastName; },
set: function(newName) { lastName = newName; },
enumerable: true
});
Object.defineProperty(person, 'fullName', {
get: function() { return firstName + " " + lastName },
set: function(fullName) {
firstName = fullName.split(" ")[0];
lastName = fullName.split(" ")[1];
}
});
person.fullName = "Jack Franklin";
console.log(person.firstName);
console.log(person.lastName);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment