From b0524df4a81b7d91f1e81cb65fa092d35d324472 Mon Sep 17 00:00:00 2001 From: Michal Nazarewicz Date: Tue, 20 Feb 2018 20:44:09 +0100 Subject: [PATCH] =?UTF-8?q?Simplify=20script=E2=80=99s=20footer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. ‘typeof foo === "undefined"’ is just a convoluted way of writing ‘foo === undefined’. The slight risk of ‘undefined’ being redefined (since it’s not a keyword) can be easily averted by using ‘void 0’. In the end, ‘typeof foo === "undefined"’ becomes ‘foo === void 0’ which is shorter and does the same thing. 2. There is really no need to use Function.prototype.call. Since the wrapper function uses it’s ‘this’ variable exactly once, whatever function run as call argument does can be moved inside of the wrapper. This shortens and simplifies script’s footer. --- lib/marked.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/marked.js b/lib/marked.js index 69b0e05e8e..06987f02b0 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -1369,14 +1369,11 @@ marked.inlineLexer = InlineLexer.output; marked.parse = marked; -if (typeof module !== 'undefined' && typeof exports === 'object') { +if (module !== void 0 && typeof exports === 'object') { module.exports = marked; } else if (typeof define === 'function' && define.amd) { define(function() { return marked; }); } else { - this.marked = marked; + (this || (window !== void 0 ? window : global)).marked = marked; } - -}).call(function() { - return this || (typeof window !== 'undefined' ? window : global); -}()); +})();