const fun = ({ aa = 1, bb = 0 } = {}) = > {
console.log('aa: ' + aa);
console.log('bb: ' + bb);
return 'hello';
}
document.body.innerHTML = fun();
Copy the code
Compiling with TSC:
Generated JavaScript code:
var fun = function (_a) {
var _b = _a === void 0 ? {} : _a, _c = _b.aa, aa = _c === void 0 ? 1 : _c, _d = _b.bb, bb = _d === void 0 ? 0 : _d;
console.log('aa: ' + aa);
console.log('bb: ' + bb);
return 'hello';
};
document.body.innerHTML = fun();
Copy the code
The readability is mediocre, so Jerry adds some notes:
var fun = function (_a) {
// Is the input parameter _a undefined? If so, assign the default value {}, an empty object. If it's not empty,
// use temporary _b to store the value of input variable _a
// now _b and _A are equivalent.
var _b = _a === void 0 ? {} : _a;
// _c stores the aa field of the input variable
var _c = _b.aa;
// Is the aa field of the input variable undefined? If so, the default value 1 is assigned to the temporary variable aa, otherwise the value of the AA field passed in by the variable is used
var aa = _c === void 0 ? 1 : _c;
// _d stores the bb field of the input variable
var _d = _b.bb;
// Is the input field bb undefined? If so, use the default value 0; otherwise, use the actual value of the bb field of the input variable
var bb = _d === void 0 ? 0 : _d;
console.log('aa: ' + aa);
console.log('bb: ' + bb);
return 'hello';
};
document.body.innerHTML = fun();
Copy the code