Skip to content

Instantly share code, notes, and snippets.

@santosh
Created October 13, 2018 02:53
Show Gist options
  • Save santosh/9ca7b0c9f39503fdc0399d62073ed4d3 to your computer and use it in GitHub Desktop.
Save santosh/9ca7b0c9f39503fdc0399d62073ed4d3 to your computer and use it in GitHub Desktop.
Constructor functions, aka Classes (in other langs)
var Car = function(maxSpeed, driver) {
this.maxSpeed = maxSpeed;
this.driver = driver;
this.drive = function(speed, time) {
console.log(speed, time);
};
this.logDriver = function() {
console.log("driver name is " + this.driver);
};
};
var myCar = new Car(140, "Santosh");
myCar.drive(50, 1);
myCar.logDriver();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment