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 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" |
function Product(first_name, last_name) {
this.first_name = first_name;
this.first_name = last_name;
}
pr = new Product('Yuuki', 'Yokoyama')
pr instanceof Product
true
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh...this is not correct way...then I got this error.