es6-函数默认参数

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
es6-函数默认参数
const add = function (a = 1, b = 2) {
  return a + b
}
const res = add()
ready
普通函数
const add = function (a, b) {
  return a + b
}
const res = add(1, 2)
ready
es6-函数默认参数(通过babel转译es5)
"use strict";

var add = function add() {
  var a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
  var b = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
  return a + b;
};
var res = add();
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.