Skip to content

Instantly share code, notes, and snippets.

@mstudio
Created March 9, 2012 17:03
Show Gist options
  • Save mstudio/2007532 to your computer and use it in GitHub Desktop.
Save mstudio/2007532 to your computer and use it in GitHub Desktop.
hwk1
//functional
function logCar(object) {
this.color = object.color;
this.make = object.make
console.log('I\'m a ' + this.color + ' ' + this.make);
}
// object-oriented
(function(window){
var Car = function(make, color){
this.make = make;
this.color = color;
};
Car.prototype.make;
Car.prototype.color;
Car.prototype.log = function(){
console.log('I\'m a ' + this.color + ' ' + this.make);
};
window.Car = Car;
}(window));
//Example call for functional version:
logCar({ color: 'blue', make: 'BMW' });
// 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