Created
November 27, 2012 13:11
-
-
Save vestige/4154168 to your computer and use it in GitHub Desktop.
561.js
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
| 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