Skip to content

Instantly share code, notes, and snippets.

@night-fury-rider
Created September 9, 2020 10:48
Show Gist options
  • Save night-fury-rider/19331674ae2bca8d5a42a168fc35daac to your computer and use it in GitHub Desktop.
Save night-fury-rider/19331674ae2bca8d5a42a168fc35daac to your computer and use it in GitHub Desktop.
Design Pattern - Prototype
var Cricketer = function(name, runs) {
this.name = name;
this.runs = runs;
};
Cricketer.prototype.getPlayerDetails = function() {
return this.name + ' has scored ' + this.runs + ' runs';
}
var player1 = new Cricketer('Sachin', 18426);
console.log(player1.getPlayerDetails()); // Sachin has scored 18426 runs 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment