Skip to content

Instantly share code, notes, and snippets.

@vestige
Created November 27, 2012 13:11
Show Gist options
  • Select an option

  • Save vestige/4154168 to your computer and use it in GitHub Desktop.

Select an option

Save vestige/4154168 to your computer and use it in GitHub Desktop.
561.js
document.writeln("\nspike");
document.writeln("2012.11.27");
var Gadget = function () {};
Gadget.isShiny = function () {
return "you bet";
};
Gadget.prototype.setPrice = function(price) {
this.price = price;
};
var iphone = new Gadget();
iphone.setPrice(500);
document.writeln(typeof Gadget.setPrice);
document.writeln(typeof iphone.isShiny);
Gadget.prototype.isShiny = Gadget.isShiny;
document.writeln(iphone.isShiny());
var Gadget = function(price) {
this.price = price;
};
Gadget.isShiny = function () {
var msg = "you bet";
if (this instanceof Gadget) {
msg += ", it costs $" + this.price + '!';
}
return msg;
};
Gadget.prototype.isShiny = function() {
return Gadget.isShiny.call(this);
};
document.writeln(Gadget.isShiny());
var a = new Gadget('499.99');
document.writeln(a.isShiny());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment