Wrap a print method similar to the one in C/Java
function print(message=' '. theArgs) {
let index = 0;
console.log(
message.replace(/%s/g.function () {
return theArgs[index++];
})
)
}
print(" 1 + 1 = %s ".1+1); // 1 + 1 = 2
Copy the code
The above… TheArgs is grammar] [remaining parameters (developer.mozilla.org/zh- CN/docs/Web/JavaScript/Reference/Functions provides/Rest_parameters)
Convert to ES5 with Babel
The React source code printing method works like this