Created
August 8, 2011 20:03
-
-
Save fauxparse/1132586 to your computer and use it in GitHub Desktop.
JS Masterclass homework
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
function logCar(options) { | |
if (options.hasOwnProperty('make') && options.hasOwnProperty('color')) { | |
console.log("I'm a " + options.color + " " + options.make); | |
} else { | |
console.log("Please supply make and color!"); | |
} | |
} | |
function Car(make, color) { | |
this.make = make; | |
this.color = color; | |
this.log = function() { | |
console.log("I'm a " + this.color + " " + this.make); | |
} | |
} |
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
Function.prototype.cached = function() { | |
if (this.hasOwnProperty('cache')) return this; | |
return (function(self) { | |
self.cache = {}; | |
return function(x) { | |
if (x in self.cache) { | |
return self.cache[x]; | |
} else { | |
return self.cache[x] = self(x); | |
} | |
} | |
})(this); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment