Created
July 8, 2019 08:11
-
-
Save peketamin/0ad458c048771959db78d1e67186c24d to your computer and use it in GitHub Desktop.
Lightweight ES5 class like object definition
This file contains hidden or 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 = { | |
init: function() { | |
this.first_name = ''; | |
this.last_name = ''; | |
return this; | |
}, | |
getFullName: function() { | |
return this.first_name + ' ' + this.last_name; | |
}, | |
}; | |
p = Person.init() | |
// {init: ƒ, getFullName: ƒ, first_name: "", last_name: ""} | |
p.first_name = 'Yuki'; | |
// "Yuki" | |
p.last_name = 'Yokoyama'; | |
// "Yokoyama" | |
p.getFullName() | |
// "Yuki Yokoyama" |
Author
peketamin
commented
Jul 8, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment