Skip to content

Commit 19496d1

Browse files
author
Vitaly Puzrin
committedJun 11, 2015
Merge pull request #82 from tomxtobin/optional-new
Make `new` optional when instantiating ArgumentParser
2 parents 19103af + cc8a376 commit 19496d1

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed
 

‎lib/argument_parser.js

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ var Namespace = require('./namespace');
5353
* [1]:http://docs.python.org/dev/library/argparse.html#argumentparser-objects
5454
**/
5555
var ArgumentParser = module.exports = function ArgumentParser(options) {
56+
if (!(this instanceof ArgumentParser)) {
57+
return new ArgumentParser(options);
58+
}
5659
var self = this;
5760
options = options || {};
5861

‎test/base.js

+8
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,12 @@ describe('base', function () {
244244
args = parser.parseArgs([ '-y' ]);
245245
});
246246
});
247+
248+
it('should support instantiation without new', function () {
249+
assert.doesNotThrow(function () {
250+
/* jshint -W064 */
251+
parser = ArgumentParser({debug: true});
252+
/* jshint +W064 */
253+
});
254+
});
247255
});

0 commit comments

Comments
 (0)
Please sign in to comment.