API Docs for: 0.1.7
Show:

otools Class

Defined in: otools.js:5

A very lightweight set of utility methods for manipulating objects, creating classes, and calling functions.

Item Index

Methods

Methods

applyNew

(
  • constructor
  • args
)
Object static

Defined in otools.js:321

Call a constructor with an array of arguments ala the Function.apply method.

Parameters:

  • constructor Function
  • args Array

Returns:

Object: A new instance of the class defined by constructor.

clone

(
  • obj
)
Object static

Defined in otools.js:13

Use the prototypal nature of javascript to clone an object such that changing any property on the clone is not reflected on the parent object, but any change to a parent property is reflected on the clone.

Parameters:

  • obj Object

Returns:

Object: The cloned object.

context

(
  • callback
  • context
)
Function static

Defined in otools.js:342

Wrap a callback function such that "this" will always point to context.

Parameters:

  • callback Function
  • context Object

Returns:

Function: The wrapped version of callback.

debounce

(
  • callback
  • [timeout]
)
static

Defined in otools.js:360

Wrap a callback so that it cannot be called more often then timeout milliseconds. If the wrapped function is called less than timeout milliseconds after the previous call, then callback will not be called and the previously returned value will be returned again.

Parameters:

  • callback Function
  • [timeout] Number optional

    Defaults to 0.

Returns:

The return value of callback.

extract

(
  • source
  • which
)
Object static

Defined in otools.js:91

Create a new object by extracting a subset of properties from another object. Only properties which are owned (hasOwnProperty) by source will be extracted.

Parameters:

  • source Object
  • which Object | Array multiple

    If which is an object then any properties of which that are owned and true will be extracted from source. If which is an array then all string values in the array that match properties on source will be extracted. if which is a function then it will be called for each property on source and the properties for which it returns true will be extracted. If which is a string then the parameter list is assumed to be variable length and all parameters starting with which will be matched against properties in source and extracted.

Returns:

Object: A new object with the extracted properties.

keys

(
  • object
)
Array static

Defined in otools.js:171

Return an array of all owned properties on object. This method will use the Object.keys method if it is present (JavaScript 1.8.5).

Parameters:

  • object Object

Returns:

Array: An array of all owned property names on object.

lazy

(
  • callback
  • [timeout]
)
static

Defined in otools.js:392

Wrap a callback so that it is called after timeout instead of immediately. If it is called a second time before the previous call has timed out, the previous call will be canceled.

Useful when you want code to execute once when the event loop becomes idle.

Parameters:

  • callback Function
  • [timeout] Number optional

    Defaults to 0.

Returns:

The timeout handle.

makeClass

(
  • [parent]
  • [prototype]
)
Function static

Defined in otools.js:203

Create a new class that inherits from parent. All properties of prototype will be added to the new class's prototype. If prototype contains its own constructor method it will be used as the constructor for the new class. The returned class constructor can be called with or without new. A this._super method is available when calling any member method to simplify calling overridden methods.

Parameters:

  • [parent] Function optional
  • [prototype] Object optional multiple

Returns:

Function: The new class constructor.

merge

(
  • [recursive]
  • target
  • [source]
)
Object static

Defined in otools.js:32

Copy properties from one or more source objects, to a target object. Only properties owned (hasOwnProperty) by the source object will be added to the target object.

Parameters:

  • [recursive] Boolean optional

    If true, property merging will be done recursively.

  • target Object
  • [source] Object optional multiple

Returns:

Object: target