使用匿名函数丑化

Uglify with anonymous function

我有一个这样的 .js,我正在压缩它:

'use strict';
!(function () {
  var object = typeof exports != 'undefined' ? exports : this;
}());

当我使用 Google 闭包编译器时,我没有收到任何错误,并且 'this' 正在引用 window 对象。 但是当我使用 Uglify(使用 mangle true 或 false)时,它在 'this' 上得到一个 undefined (所以对象是 undefined 并且我收到错误)。有谁知道为什么?

基本上,我可以将其更改为 window,它会起作用,但我担心的是其他代码、库或其他我将来会讨厌的东西。

注意:我使用的是带有以下选项的 grunt-contrib-uglify 插件: mangle: true, preserverComments: false, sourceMap: true

这是预期的行为:

'use strict'; 函数的上下文是 undefined,不是全局对象。