Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #93 from Mithgol/patch-1

make the `new` operator optional before the `JSZip` constructor
  • Loading branch information...
commit a336db31348de9c36d1b51e6819cff56dd900ab1 2 parents 4c461bf + 06cd947
@Stuk authored
Showing with 7 additions and 2 deletions.
  1. +3 −1 lib/index.js
  2. +4 −1 test/test.js
View
4 lib/index.js
@@ -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
View
5 test/test.js
@@ -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"); // {{{
Please sign in to comment.
Something went wrong with that request. Please try again.