Javascript Object Constructor

James Hamann
Sep 14, 2016 · 2 min read
var car {
colour = "Red";
model = "Lexus";
year = "2016"
seats = 5;
engineType = "Hybrid";
function car(colour, model, year, seats, engine) {
this.colour = colour;
this.model = model;
this.year = year;
this.seats = seats;
this.engineType = engine;
var lexus = new car("Red","Lexus","2016",5,"Hybrid");
var ford = new car ("Blue","Ford","2014",5,"Petrol");
console.log(lexus.colour); --> Red
console.log(ford.year); --> 2014

James Hamann

Written by

Software Developer

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade