Why were ES5 Object methods not added to Object.prototype?

前端 未结 2 1303
无人及你
无人及你 2020-11-28 14:52

ES5 added a number of methods to Object, which seem to break the semantic consistency of JavaScript.

For instance, prior to this extension, the JavaScri

2条回答
  •  难免孤独
    2020-11-28 15:24

    the JavaScript API always revolved around operarting on the object itself;

    This is not correct. E.g. JSON and Math always had own methods. Nobody does such things:

    var x = 0;
    x.cos(); // 1.0
    ({"a":[0,1],"p":{"x":3,"y":4}}).toJSON();
    

    There are numerous articles on the web about why extending Object.prototype is a bad thing. Yes, they're about client code, but maybe this is bad for build-in methods also for some points.

提交回复
热议问题