As far as I know minifiers don't do this since it changes semantics. Take this for example:
// 1
doSomething();
console.log(Math.sin(2));
// 2
var s = Math.sin;
doSomething();
console.log(s(2));
Now, consider this definition for `doSomething()`:
function doSomething() {
Math.sin = x => x
}
Now, the first prints 2 and the second snippet prints 0.9092.
Keeping track of globals to get around this is complicated. Even if you do, you can't always be sure the behaviour of the code isn't changing since `doSomething` could be defined in a module your minifier doesn't know about.
aylmao|6 years ago
Keeping track of globals to get around this is complicated. Even if you do, you can't always be sure the behaviour of the code isn't changing since `doSomething` could be defined in a module your minifier doesn't know about.