Created
March 3, 2011 21:09
-
-
Save mason-stewart/853571 to your computer and use it in GitHub Desktop.
more testing
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
<script> | |
// 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. | |
// Example call for functional version: | |
logCar({ color: 'blue', make: 'BMW' }); | |
// Example call for OO version: | |
(new Car('Ferrari', 'red')).log(); | |
var Car = function(make, color){ | |
this.make = make; | |
this.color = color; | |
this.logCar = function() { | |
return 'I\'m a ' + this.color + ' ' + this.make; | |
} | |
var car = { | |
logCar: function() { | |
return 'I\'m a ' + this.color + ' ' + this.make; | |
} | |
} | |
car.make = 'honda'; | |
car.color = '#FC9901' | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment