Extending Number.prototype in javascript and the Math object?

后端 未结 8 2090
孤城傲影
孤城傲影 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 believe calling it this way works as well, since Number's prototype functions work just like every other Object's prototype functions do:

    5.5["round"]();
    //should return 6
    

提交回复
热议问题