A Pen by Andrew Kirchmyer on CodePen.
A Pen by Andrew Kirchmyer on CodePen.
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
| var Gadget = function() {}; | |
| // static method | |
| Gadget.isShiny = function() { | |
| return 'you bet'; | |
| }; | |
| // normal method added to prototype | |
| Gadget.prototype.setPrice = function(price) { | |
| this.price = price; |
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
| var Gadget = (function() { | |
| // static property | |
| var counter = 0, | |
| NewGadget; | |
| // new constructor implementation | |
| NewGadget = function() { | |
| // in this way, counter can become a unique identifier for each instance | |
| counter+=1; | |
| }; |
A Pen by Andrew Kirchmyer on CodePen.
A Pen by Andrew Kirchmyer on CodePen.
A Pen by Andrew Kirchmyer on CodePen.
A Pen by Andrew Kirchmyer on CodePen.
A Pen by Andrew Kirchmyer on CodePen.
A Pen by Andrew Kirchmyer on CodePen.