3 ms·
In the final, minified code there's a lot of calls to Math methods (sin, cos, tan). I wonder if there's potential to shrink this even more with some assignments
by aylmao 7y ago
In the final, minified code there's a lot of calls to Math methods (sin, cos, tan). I wonder if there's potential to shrink this even more with some assignments:
M=Math,s=M.sin,c=M.cos,p=M.PI,a=M.abs; // etc.
- zachrip 7y agoCould alternatively make use of `with`
- carterehsmith 7y agoThat's what minifiers/uglifiers do? Perhaps OP did not want to use them.
- aylmao 7y agoAs 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.