Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Day401:实现一个数字加减法功能(腾讯) #404

Open
qappleh opened this issue Sep 18, 2021 · 1 comment
Open

Day401:实现一个数字加减法功能(腾讯) #404

qappleh opened this issue Sep 18, 2021 · 1 comment

Comments

@qappleh
Copy link
Owner

qappleh commented Sep 18, 2021

例如:

(5).add(3).minus(2)
5 + 3 - 2 = 6
3 - 1 + 2 = 4
@Moushudyx
Copy link

Object.defineProperties(Number.prototype, {
  add: { // 加
    value: function (num) { return this + num; }
  },
  sub: { // 减
    value: function (num) { return this - num; }
  }
});
(5).add(3).sub(2); // 6

如上,我只能想到直接扩展原生对象的方式。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants