Last active
August 29, 2015 14:14
-
-
Save KKrisu/705f48772b6981f06722 to your computer and use it in GitHub Desktop.
Playing with ES5
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
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
'use strict'; | |
// Object get&set | |
var obj = { | |
firstname: 'Grzegorz', | |
lastname: 'Brzęczyk', | |
get fullName () { | |
return this.firstname + ' ' + this.lastname; | |
}, | |
set fullName (full) { | |
var parts = full.split(' '); | |
this.firstname = parts[0]; | |
this.lastname = parts[1]; | |
} | |
}; | |
console.log(obj.fullName); // Grzegorz Brzęczyk | |
obj.fullName = 'Jan Drwal'; | |
console.log(obj.fullName); // Jan Drwal | |
// Object.defineProperty | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment