Making Object Literals a sub-class of Object

Brian Ninni ninni.brian at gmail.com
Fri Oct 14 13:36:51 UTC 2016


>
> `({}).toString.call(o);`


This does work for all Native class, but still returns "[object Object] "
for user created classes

`Object.getPrototypeOf({}) === Object.prototype // true`


Did not know of that method.  Seems like a roundabout way, but it works.

`Object.prototype.isPrototypeOf(o)`


Doesn't seem to differentiate between Literals and non-Literals.

Guylian's solution solves my main issue, so definitely not worth breaking a
lot of code for.

I can see the possibility of someone wanting to extend the prototype for
Object Literals only, and not all Objects, but that can also be
accomplished by making a new class.  So again, not a great reason for
breaking code.

Thanks for the responses

On Fri, Oct 14, 2016 at 9:24 AM, Bergi <a.d.bergi at web.de> wrote:

> Brian Ninni wrote:
>
> On more than one occasion I've had to determine whether something was a
>> plain old Object, or some other class. This involves checking that the
>> given object was NOT an instanceof any other acceptable class.
>>
>
> `Object.prototype.isPrototypeOf(o)` should do that (if you don't care
> about other realms).
>
> Array, RegExp, Function, and Class Literals all already create an Object
>> sub-class, so why not Object Literals?
>>
>
> Because Object-objects are just Objects and not anything special that
> would need a subclass with specific methods.
>
> Are there any other major reasons why this is a bad idea?
>>
>
> As you already said, it would break a great lot of code.
>
> - Bergi
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20161014/7875a321/attachment.html>


More information about the es-discuss mailing list