otools Class
A very lightweight set of utility methods for manipulating objects, creating classes, and calling functions.
Item Index
Methods
applyNew
-
constructor -
args
Call a constructor with an array of arguments ala the Function.apply method.
Parameters:
-
constructorFunction -
argsArray
Returns:
clone
-
obj
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:
-
objObject
Returns:
context
-
callback -
context
Wrap a callback function such that "this" will always point to context.
Parameters:
-
callbackFunction -
contextObject
Returns:
debounce
-
callback -
[timeout]
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:
-
callbackFunction -
[timeout]Number optionalDefaults to 0.
Returns:
extract
-
source -
which
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:
-
sourceObject -
whichObject | Array multipleIf 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:
keys
-
object
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:
-
objectObject
Returns:
lazy
-
callback -
[timeout]
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:
-
callbackFunction -
[timeout]Number optionalDefaults to 0.
Returns:
makeClass
-
[parent] -
[prototype]
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:
merge
-
[recursive] -
target -
[source]
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 optionalIf true, property merging will be done recursively.
-
targetObject -
[source]Object optional multiple
