Created
December 9, 2018 17:16
-
-
Save pimoGit/d148451dd44148c72784eaae539ba03d to your computer and use it in GitHub Desktop.
One of the most popular way to deal with objects in Javascript that I don't like anymore
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
function Person(name, nick) { | |
this.name = name; | |
this.nick = nick; | |
} | |
Person.prototype.changeNick = function(nick) { | |
this.nick = nick; | |
}; | |
// added for demonstration | |
Person.prototype.identify = function() { | |
console.log( "I am " + this.name + " and my nickname is " + this.nick); | |
}; | |
var laura = new Person("Laura", "javaScripter89"); | |
// added for demonstration | |
laura.identify(); | |
laura.changeNick("fullastak89!"); | |
laura.identify(); | |
var mario = new Person("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 "trend way" that I don't like anymore.
This is the way I love: https://gist.github.com/pimoGit/13449542eb7b6855d425f9a615e37aed