利用参数默认值,可以指定某一个参数不得省略,如果省略就抛出一个错误

  function throwIfMissing() {
    throw new Error('Missing parameter');
  }

  function foo(mustBeProvided = throwIfMissing()) {
    return mustBeProvided;
  }

  foo();

猜你喜欢

转载自blog.csdn.net/Wangdanting123/article/details/84940191