Skip to content

Array and Object have different values in REPL and in files #7788

Closed
@calebsander

Description

@calebsander
  • Version: v6.3.0
  • Platform: 4.4.0-31-generic #50-Ubuntu SMP Wed Jul 13 00:07:12 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

I have one file, say is.js, that contains the following:

exports.isObject = (obj) => obj.constructor === Object
exports.isNumber = (obj) => obj.constructor === Number

In the console, require('./is.js').isObject({}) returns false. However, ({}).constructor === Object returns true. Strangely, isNumber(2) works as expected. When required from another file, everything works as expected.

Affected classes:

  • Object
  • Array
  • Date
  • Error
  • RegExp

Unaffected classes:

  • Number
  • String
  • Boolean
  • Map
  • Set
  • Symbol
  • Typed arrays

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.replIssues and PRs related to the REPL subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions