Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

scripts should be wrapped in IIFEs on concatenation #25

Open
pwasem opened this issue Nov 11, 2015 · 0 comments
Open

scripts should be wrapped in IIFEs on concatenation #25

pwasem opened this issue Nov 11, 2015 · 0 comments

Comments

@pwasem
Copy link

pwasem commented Nov 11, 2015

Scripts should each be wrapped in immediately invoked function expressions (IIFEs) on concatenation as mentioned in Effective Javascript by David Herman (chapter 1).
This would avoid several problems, e.g. considering scopes and usage of "use strict";

So instead of:

script_1;
script_2;
...
script_n;

The concatenated file should look like:

(function (){
  script_1
})();
(function (){
  script_2
})();
...
(function (){
  script_n
})();

Implementation should be easy:

var content = dom5.getTextContent(sn).trim();
// wrap content in immediately invoked function expression (IIFE)
let iifeContent = '(function(){\n' + content + '\n})();'
contents.push(iifeContent);

Thank you in advance!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant