Skip to content

Instantly share code, notes, and snippets.

@jamesmenera
Last active December 14, 2015 15:58
Show Gist options
  • Save jamesmenera/5111655 to your computer and use it in GitHub Desktop.
Save jamesmenera/5111655 to your computer and use it in GitHub Desktop.
Homework 1
// 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.
//Two solutions, one with a constructor only, and one using prototypes
// Example call for functional version:
var logCar = function(car) {
console.log('I\'m a ' + car.color + ' ' + car.make);
}
logCar({ make: 'Red', car: 'Ferrari' });
// Example call for OO version:
Car = function(color, model){
return console.log('I\'m a ' + color + model');
}
(new Car('Ferrari', 'red')).log();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment