Extending Number.prototype in javascript and the Math object?

后端 未结 8 1754
孤城傲影
孤城傲影 2021-02-05 03:11

I\'ve always wondered why Javascript has the global Math object instead of giving numbers their own methods. Is there a good reason for it?

Also are there any drawbacks

8条回答
  •  清酒与你
    2021-02-05 03:32

    I think Math is more than set of Number methods. It's usage wider. Say, using NumberVariable.PI can be confusing. Same with random numbers generation.

    Also I think extending number is OK, because it's the part of JS nature. Maybe someone will correct me if I am wrong here.

提交回复
热议问题