Created
December 12, 2011 20:41
-
-
Save stdclass/1468994 to your computer and use it in GitHub Desktop.
js master class - phillipdornauer
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
// Exercise 1 - OO || !OO | |
// Define a data structure for cars (make and color), and a function | |
// that logs a string like "I'm a red Mercedes" to the console. | |
// Make two versions: a functional version, and a object-oriented version. | |
function logCar( car ){ | |
console.log("I'm a " + car.color + " " + car.make); | |
}; | |
// Example call for functional version: | |
logCar({ color: 'blue', make: 'BMW' }); | |
function Car( make, color ){ | |
this.make = make; | |
this.color = color; | |
}; | |
Car.prototype = { | |
log: function(){ | |
return "I'm a " + this.color + " " + this.make; | |
} | |
}; | |
// Example call for OO version: | |
(new Car('Ferrari', 'red')).log(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment