Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make the new operator optional before the JSZip constructor #93

Merged
merged 3 commits into from
Feb 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ Usage:
* @param {Object=} options the options for creating this objects (optional).
*/
function JSZip(data, options) {
// if this constructor is used without `new`, it adds `new` before itself:
if(!(this instanceof JSZip)) return new JSZip(data, options);

// object containing the files :
// {
// "folder/" : {...},
// "folder/data.txt" : {...}
// }

this.files = {};

// Where we are in the hierarchy
Expand Down
5 changes: 4 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ test("JSZip", function(){
ok(JSZip, "JSZip exists");

var zip = new JSZip();
ok(zip, "Constructor works");
ok(zip instanceof JSZip, "Constructor works");

var zipNoNew = JSZip();
ok(zipNoNew instanceof JSZip, "Constructor adds `new` before itself where necessary");
});

QUnit.module("Essential"); // {{{
Expand Down