Skip to content

Object.map causing errors in the browser and some tests #12

@dphaener

Description

@dphaener

There's something weird going on with Object.map. It's causing the following error in Chrome:

Uncaught TypeError: Cannot assign to read only property 'map' of #<Object>

It looks like it's happening inside of React somewhere. Not sure if React defines this, or tries to assign to it?

It happens here:

/**
     * Executes the provided `callback` once for each enumerable own property in the
     * object and constructs a new object from the results. The `callback` is
     * invoked with three arguments:
     *
     *  - the property value
     *  - the property name
     *  - the object being traversed
     *
     * Properties that are added after the call to `mapObject` will not be visited
     * by `callback`. If the values of existing properties are changed, the value
     * passed to `callback` will be the value at the time `mapObject` visits them.
     * Properties that are deleted before being visited are not visited.
     *
     * @grep function objectMap()
     * @grep function objMap()
     *
     * @param {?object} object
     * @param {function} callback
     * @param {*} context
     * @return {?object}
     */
    function mapObject(object, callback, context) {
      if (!object) {
        return null;
      }
      var result = {};
      for (var name in object) {
        if (hasOwnProperty.call(object, name)) {
          result[name] = callback.call(context, object[name], name, object);
        }
      }
      return result;
    }

    module.exports = mapObject;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions