Last active
December 9, 2018 18:28
-
-
Save pimoGit/13449542eb7b6855d425f9a615e37aed to your computer and use it in GitHub Desktop.
One of the less popular way to deal with objects in Javascript that I love
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 personHelper = { | |
init: function(name, nick) { | |
this.name = name; | |
this.nick = nick; | |
}, | |
identify: function() { | |
console.log( "I am " + this.name + " and my nickname is " + this.nick); | |
} | |
}; | |
var person = Object.create(personHelper); | |
person.changeNick = function(nick) { | |
this.nick = nick; | |
}; | |
var laura = Object.create( person ); | |
laura.init( "Laura", "javaScripter89"); | |
laura.identify(); | |
laura.changeNick("fullastak89!"); | |
laura.identify(); | |
var mario = Object.create( person ); | |
mario.init( "Mario", "csharperr80"); | |
mario.identify(); | |
mario.changeNick("datascientist80!"); | |
mario.identify(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a gist just to be embedded in a nice way, into my post titled: "WRITING JAVASCRIPT THAT ACTS LIKE JAVASCRIPT
Behavior Delegation - OLOO pattern."
This part is the "OLOO way" that I love.
This is compared with the previous here: https://gist.github.com/pimoGit/d148451dd44148c72784eaae539ba03d