PolymerLabs / crisper

BSD 3-Clause "New" or "Revised" License
106 stars 22 forks source link

scripts should be wrapped in IIFEs on concatenation #26

Closed pwasem closed 2 years ago

pwasem commented 9 years ago

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);
googlebot commented 9 years ago

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


googlebot commented 9 years ago

CLAs look good, thanks!

pwasem commented 8 years ago

Any thoughts on this one yet?