Skip to content

Instantly share code, notes, and snippets.

@msankhala
Created December 19, 2021 08:16
Show Gist options
  • Save msankhala/805c4fbb25554180bdb923db6b0dd2c8 to your computer and use it in GitHub Desktop.
Save msankhala/805c4fbb25554180bdb923db6b0dd2c8 to your computer and use it in GitHub Desktop.
Prototype design pattern javascript
const atv = {
make: 'Honda',
model: 'Rincon 650',
year: 2018,
mud: () => {
console.log('Mudding');
}
};
const secondATV = Object.create(atv);
// or
const atvPrototype = {
mud: () => {
console.log('Mudding');
}
};
function Atv(make, model, year) {
function constructor(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}
constructor.prototype = atvPrototype;
let instance = new constructor(make, model, year);
return instance;
};
const atv1 = Atv();
const atv2 = Atv('Honda', 'Rincon 650', '2018');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment