Skip to content

factor out isMergeable #83

@pixelzoom

Description

@pixelzoom

merge.js has private function validateMergeableObject that contains this nice validation:

assert && assert( object === null ||
                    ( object && typeof object === 'object' &&
                      Object.getPrototypeOf( object ) === Object.prototype ),
    'Object should be null or a truthy object that cannot have an extra prototype' );

A similar test seems to be duplicated many times throughout the PhET code base. Search for getPrototypeOf shows 62 occurrences, and it looks like most of these are doing the same thing as validateMergeableObject -- type validation of options arg.

Would anyone object to factoring out isMergeable?

function isMergeable( object ) {
  return ( object === null ||
    ( object && typeof object === 'object' && Object.getPrototypeOf( object ) === Object.prototype ) );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions