0

Object sits at the very base of the JS Data-Structures. Whatever other data-types we say (Arrays, Promises, Date, Strings, Numbers, Functions, Boolean, Maps, Sets, etc.) --- have Object as their upstream in the prototype chain so they may access all its properties and methods.

Now, even Object has got a set of its own properties & methods, which it might access when it needs.

Object.prototype gives set of its properties and methods.

Object.assign Now returns some function.

The strange thing is I expected assign() function to be a method up in the Object-prototype chain. Why is it not present? Shouldn't ideally be it should be there ?? If NOT, how object is able to use it?

Also, Object.prototype.prototype will give you null as there is nothing above it.

consider:

enter image description here

Deadpool
  • 7,811
  • 9
  • 44
  • 88
  • How to the above 2 links explain my question? It is so bad, that nowadays people just come and mark duplicate, when my question is not explained in those 2 links given. – Deadpool Jun 10 '21 at 02:17
  • "*I expected assign() function to be a method up in the Object-prototype chain. Why is it not present? Shouldn't ideally be it should be there?*" is exactly the question that those two canonicals answer (sure, they were asked about ES5, but the same design methodology applies to ES6 `Object.assign`). Were you asking something else? – Bergi Jun 10 '21 at 02:21
  • Yes, but we may only use items which are in `prototype`. So, since when this new way started? Was is started in ES6, ES7, ES8, or from before. If so, why the rest of properties and methods are present in `Object.prototype`? They should also not be present. Why is the separate behavior with `Object.assign()`? How will the end user then find, what exactly is list of methods that can be used with `Object, array, string` or whatever then. It becomes so obscure and unlisted then. – Deadpool Jun 10 '21 at 02:25
  • "*but we may only use items which are in `prototype`*" - no. Since ES1, all you need to define a method is an object (including [function objects](https://stackoverflow.com/q/8588563), see also [here](https://stackoverflow.com/q/705173)) with a function property. "*Why is the separate behavior with Object.assign()?*" - `Object.assign` is by far not the only static native method. `Array.isArray`, `Object.create`, `Map.from`…. "*How will the end user then find, what exactly is list of methods*" - by reading [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects). – Bergi Jun 10 '21 at 02:33

0 Answers0