sof
sof

Reputation: 9649

Using Underscore to check own property

Used Underscore to check if the global object owns parseInt function on Nodejs console,

U = require('underscore')

U.contains(U.keys(global), 'parseInt') // false

U.has(global, 'parseInt') // true

Why did it give contrary results above?

Upvotes: 0

Views: 118

Answers (1)

loganfsmyth
loganfsmyth

Reputation: 161457

Object.keys returns the object properties that have their descriptors marked enumerable. In this case, parseInt is not enumerable:

e.g.

Object.getOwnPropertyDescriptor(global, 'parseInt')

is

{
    "writable":true,
    "enumerable":false,
    "configurable":true,
    "value": function parseInt(){ ...}
}

Upvotes: 1

Related Questions