Skip to content

Instantly share code, notes, and snippets.

@pimoGit
Last active Dec 9, 2018
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@pimoGit 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