实现 (5).add(3).minus(2),使其输出结果为:6

function check(n) {
  n = Number(n);
  return isNaN(n) ? 0 : n;
}
function add(n) {
  n = check(n);
  return this + n;
}
function minus(n) {
  n = check(n);
  return this - n;
}
Number.prototype.add = add;
Number.prototype.minus = minus;

console.log((5).add(3).minus(2));
posted @ 2020-03-31 19:37  YuTing-721  阅读(241)  评论(0编辑  收藏  举报