Skip to content

add internal utility for defining "type" property #88

@dwhieb

Description

@dwhieb

Add an internal factory method utility for defining the type property on a model.

/**
 * A factory function that adds a `type` field to an Object
 * @param  {Object} object The Object to add the `type` field to
 * @param  {String} type   The name of the type to add
 * @return {Object}        Returns the original object
 */
function addType(object, type) {

  Object.defineProperty(object, `type`, {
    configurable: false,
    enumerable:   true,
    get() { return type; },
  });

  return object;

}

Metadata

Metadata

Assignees

Labels

coreCore models and utilities

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions