Created
December 19, 2021 08:16
-
-
Save msankhala/805c4fbb25554180bdb923db6b0dd2c8 to your computer and use it in GitHub Desktop.
Prototype design pattern javascript
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
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