only()

Creates a new object with only the specified keys copied from the specified object to this new object.

This function is valid in v2.14.2 to v2.18.1. This function has been downloaded 14 times.

Parameters

{Object|undefined} opt_subject
If undefined this indicates that a partial function will be returned. Otherwise this is the object from which the properties should be copied.
{Array|Function} keys
If this is an array it must be the keys of the subject to be copied to the new object. If this is a function it will be called for each key/value pair (receiving the key as argument 1 and the value as argument 2) and whenever the return value is true-ish the key/value pair will be copied to the new object.
{*=} opt_initial Optional, Default:{}
If given this is the object that will be returned and into which the properties will be copied.

Returns

{*}
If opt_subject was given opt_initial with the specified keys copied into it will be returned. Otherwise a partial function will be returned which will accept (1) the mandatory object from which to copy the properties and (2) the optional initial object that will be augmented and returned.

Required Functions

This function requires the following functions which are included automatically:

  • has()
    Every object descended from Object inherits the hasOwnProperty method. This method can be used to determine whether an object has the specified property as a direct property of that object; unlike the in operator, this method does not check down the object's prototype chain.
  • entries()
    Gets an array of pairs (array of length 2) indicating all of the keys and values within a given array or object.