On Fri, Oct 14, 2016 at 9:05 AM Brian Ninni wrote:
> I did a quick search and didn't find any recent mentions of this topic.
>
> 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
Object literals (object initializers) are just a convenient way to create a new
ordinary object which (initially) inherits from `Object.prototype`, and
populate it with some properties.
I don't think you should be able to distinguish them from similar objects not
created using object initialize
>
> `({}).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)`
I 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
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
If you want to check that your variable is a plain old object and not some
other class, you can use
`Object.getPrototypeOf(x) === Object.prototype`
`Object.getPrototypeOf({}) === Object.prototype // true`
`Object.getPrototypeOf(new Map()) === Object.prototype // false`
Le ven. 14 oct. 2016 à 15
2016-10-14 15:05 GMT+02:00 Brian Ninni :
> I did a quick search and didn't find any recent mentions of this topic.
>
> 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 instance
7 matches
Mail list logo