Last active February 22, 2023 10:48
Save mattdesl/d074d956f07821f7d3bb to your computer and use it in GitHub Desktop.
avoiding new in classes
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 // Allows: // funkyParser() module.exports = function createFunkyParser(opt) { return new FunkyParser(opt) } function FunkyParser(opt) { // make params optional opt = opt || {} this.foo = opt.foo || 'default' // handle other options... ... } 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 // Allows: // funkyParser() // new funkyParser() module.exports = FunkyParser function FunkyParser (opt) { // hide "new" if (!(this instanceof FunkyParser)) return new FunkyParser(opt) opt = opt || {} }You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4