From cfe05dba37fc89cbd5bcbd661f6813b84af788f4 Mon Sep 17 00:00:00 2001 From: Felquis Gimenes Date: Mon, 3 Oct 2016 11:41:12 -0300 Subject: [PATCH] Use 'instanceOf' to make the use of 'new' optional (#191) * Use 'instanceOf' to make the use of 'new' optional * Should work as usual when used without new * v1.4.2 --- fingerprint2.js | 3 +++ package.json | 2 +- specs/specs.js | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/fingerprint2.js b/fingerprint2.js index 95d194bb1..8678c6fa8 100644 --- a/fingerprint2.js +++ b/fingerprint2.js @@ -54,6 +54,9 @@ }; } var Fingerprint2 = function(options) { + + if (!(this instanceof Fingerprint2)) return new Fingerprint2(options) + var defaultOptions = { swfContainerId: "fingerprintjs2", swfPath: "flash/compiled/FontList.swf", diff --git a/package.json b/package.json index 58c5c583a..5ab7ebdac 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fingerprintjs2", - "version": "1.4.1", + "version": "1.4.2", "description": "Modern & flexible browser fingerprinting library", "main": "dist/fingerprint2.min.js", "devDependencies": { diff --git a/specs/specs.js b/specs/specs.js index dffa4481c..054104baf 100644 --- a/specs/specs.js +++ b/specs/specs.js @@ -43,6 +43,12 @@ describe("Fingerprint2", function () { }); }); + describe("without new keyword", function () { + it("creates a new instance of FP2", function () { + expect(Fingerprint2()).not.toBeNull(); + }); + }) + describe("get", function () { describe("default options", function () { it("calculates fingerprint", function (done) {