Print Friendly

# Class Function

Package: | Global
Class: | Function
Extends: | Object
Defined In: | yutil.js

## Public Properties

This class has no public properties.

## Public Methods

Method | Defined By
--- | ---
| createCallback() : Function | Function
Creates a callback that passes arguments[0], arguments[1], arguments[2], ... Call directly on any function. Example: ...
| createDelegate([`Object obj`], [`Array args`], [`Boolean/Number appendArgs`]) : Function | Function
Creates a delegate (callback) that sets the scope to obj. Call directly on any function. Example: this.myFunction.cre...
| createInterceptor(`Function fcn`, [`Object scope`]) : Function | Function
Creates an interceptor function. The passed fcn is called before the original one. If it returns false, the original ...
| createSequence(`Function fcn`, [`Object scope`]) : Function | Function
Create a combined function call sequence of the original function + the passed function. The resulting function retur...
| defer(`Number millis`, [`Object obj`], [`Array args`], [`Boolean/Number appendArgs`]) : Number | Function
Calls this function after the number of millseconds specified.

## Public Events

This class has no public events.

## Method Details

### createCallback

`public function createCallback()`
Creates a callback that passes arguments[0], arguments[1], arguments[2], ... Call directly on any function. Example: `myFunction.createCallback(myarg, myarg2)` Will create a function that is bound to those 2 args.
Parameters:

- None.

Returns:

- `Function`
  The new function

This method is defined by Function.

### createDelegate

`public function createDelegate([`Object obj`], [`Array args`], [`Boolean/Number appendArgs`])`
Creates a delegate (callback) that sets the scope to obj. Call directly on any function. Example: `this.myFunction.createDelegate(this)` Will create a function that is automatically scoped to this.
Parameters:

- `obj` : Object
  (optional) The object for which the scope is set
- `args` : Array
  (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
- `appendArgs` : Boolean/Number
  (optional) if True args are appended to call args instead of overriding, if a number the args are inserted at the specified position

Returns:

- `Function`
  The new function

This method is defined by Function.

### createInterceptor

`public function createInterceptor(`Function fcn`, [`Object scope`])`
Creates an interceptor function. The passed fcn is called before the original one. If it returns false, the original one is not called. The resulting function returns the results of the original function. The passed fcn is called with the parameters of the original function. @addon
Parameters:

- `fcn` : Function
  The function to call before the original
- `scope` : Object
  (optional) The scope of the passed fcn (Defaults to scope of original function or window)

Returns:

- `Function`
  The new function

This method is defined by Function.

### createSequence

`public function createSequence(`Function fcn`, [`Object scope`])`
Create a combined function call sequence of the original function + the passed function. The resulting function returns the results of the original function. The passed fcn is called with the parameters of the original function
Parameters:

- `fcn` : Function
  The function to sequence
- `scope` : Object
  (optional) The scope of the passed fcn (Defaults to scope of original function or window)

Returns:

- `Function`
  The new function

This method is defined by Function.

### defer

`public function defer(`Number millis`, [`Object obj`], [`Array args`], [`Boolean/Number appendArgs`])`
Calls this function after the number of millseconds specified.
Parameters:

- `millis` : Number
  The number of milliseconds for the setTimeout call
- `obj` : Object
  (optional) The object for which the scope is set
- `args` : Array
  (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
- `appendArgs` : Boolean/Number
  (optional) if True args are appended to call args instead of overriding, if a number the args are inserted at the specified position

Returns:

- `Number`
  The timeout id that can be used with clearTimeout

This method is defined by Function.

Copyright © 2006 Jack Slocum. All rights reserved.