-
-
Save mstudio/2007532 to your computer and use it in GitHub Desktop.
hwk1
This file contains hidden or 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
//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