Skip to content

Instantly share code, notes, and snippets.

@fauxparse
Created August 8, 2011 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fauxparse/1132586 to your computer and use it in GitHub Desktop.
Save fauxparse/1132586 to your computer and use it in GitHub Desktop.
JS Masterclass homework
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);
}
}
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