Skip to content

Instantly share code, notes, and snippets.

@pimoGit
Last active December 9, 2018 18:28
Show Gist options
  • Save pimoGit/13449542eb7b6855d425f9a615e37aed to your computer and use it in GitHub Desktop.
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
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();
@pimoGit
Copy link
Author

pimoGit commented Dec 9, 2018

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

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