Skip to content

Instantly share code, notes, and snippets.

@peketamin
Created July 8, 2019 08:11
Show Gist options
  • Save peketamin/0ad458c048771959db78d1e67186c24d to your computer and use it in GitHub Desktop.
Save peketamin/0ad458c048771959db78d1e67186c24d to your computer and use it in GitHub Desktop.
Lightweight ES5 class like object definition
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"
@peketamin
Copy link
Author

peketamin commented Jul 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment