Stuk/jszip — pull request #93 by Mithgol (2014-02-11 15:51:09+00:00)
Title: make the `new` operator optional before the `JSZip` constructor

As @qlqllu has [reported](https://github.com/Stuk/jszip/issues/89#issuecomment-34730705), an attempt to shorten JSZip call (giving it the form `var jsZIP = new require('jszip')()`) fails.

The failure's cause is a well-known JavaScript's [operator precedence](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence) (the operator `new` has higher precedence than a function call — **even if** Node's `require` is that function). However, frankly speaking, that precedence in this case looks counter-intuitive to me as well.

This case reminded me of John Resig's self-calling constructor pattern (given in Resig's blog entry *[Simple “Class” Instantiation](http://ejohn.org/blog/simple-class-instantiation/)* in 2007). Nobody uses `new $` with Resig's jQuery and, I think, JSZip might follow jQuery's example and benefit from it.

This pull request makes the `new` operator **optional** before JSZip's constructor. Programmers might continue using `new` or omit it, depending on their inner personal preferences:

* not typing four characters (`new` + space) might feel more [RAD](http://en.wikipedia.org/wiki/Rapid_application_development "Rapid application development") and less [boilerplate code](http://en.wikipedia.org/wiki/Boilerplate_code);

* typing `new` might feel like reminding that a constructor call is ahead;

* using `someZIP = require('jszip')()` instead of `someZIP = new (require('jszip'))()` means less brackets;

* etc.

(Unlike the example in Resig's blog, this pull request refrains from using `arguments.callee` because the use of that property is [believed](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/arguments/callee) to slow down the engine.)

This change is a backwards-compatible feature. An `npm publish` of a newer package's version (non-major) is recommended.