* Flip default parameter template YMMV, I saved ~10b on a 2kb library. Not noticeable at the small scale, by why not do it anyway? I've (unscientifically) found that flipping the default parameter conditional yields better gzip results. I think this is due to the slightly longer string it can now repeatedly match: ```js // old var param = arguments.length <= 0 || void 0 === arguments[0] ? null : arguments[0] --------------------------------------------------------------^ // new var param = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : null ------------------------------------------------------------------------^ ``` Though it's entirely likely gzip will also choose up to the index of the arguments if you many default parameters at different indexes. * Update tests
13 lines
359 B
JavaScript
13 lines
359 B
JavaScript
// #3861
|
|
function t() {
|
|
var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "default";
|
|
var _ref = arguments[1];
|
|
var a = _ref.a;
|
|
var b = _ref.b;
|
|
|
|
for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
args[_key - 2] = arguments[_key];
|
|
}
|
|
|
|
console.log(x, a, b, args);
|
|
} |