Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save silviud/2ec249352c42ac65e451e76917ba4af2 to your computer and use it in GitHub Desktop.
Save silviud/2ec249352c42ac65e451e76917ba4af2 to your computer and use it in GitHub Desktop.
Class, Constructor, Factory
// class
class ClassCar {
drive () {
console.log('Vroom!');
}
}
const car1 = new ClassCar();
console.log(car1.drive());
// constructor
function ConstructorCar () {}
ConstructorCar.prototype.drive = function () {
console.log('Vroom!');
};
const car2 = new ConstructorCar();
console.log(car2.drive());
// factory
const proto = {
drive () {
console.log('Vroom!');
}
};
const factoryCar = () => Object.create(proto);
const car3 = factoryCar();
console.log(car3.drive());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment