Create a new function by wrapping an existing function in another existing function... |
The parameters to newFn are passed to innerFn. The return value of innerFn is passed as the sole parameter to outerFn (the wrapper) and the return value of outerFn is then passed to the calling script...
var newFn = outerFn.wraps(innerFn); result = newFn(args...); |
Parameter / Function | Type | Mandatory | Description | API Version |
---|---|---|---|---|
innerFn | Function | ![]() | The inner function that will be called first with the arguments passed in to newFn | 1.0 |
outerFn | Function | ![]() | The outer function that will be called second with a single argument that is the return value of innerFn.
| 1.0 |
args... | Variant | ![]() | When calling newFn you can optionally specify one or more arguments that will be passed to innerFn | 1.0 |
Value | Type | Description | Util.js version |
---|---|---|---|
newFn | Function | A new function based on the composition of innerFn and outerFn | 1.0 |
<result> | Variant | The return value of the new function is derived as follows:
| 1.0 |
var roundedSqRoot = Math.round.wraps(Math.sqrt); roundedSqRoot(28); // 5 // Here's why: // 1. Math.sqrt(28) → 5.291502622129181 // 2. Math.round(5.291502622129181) → 5 |
Availability Requires:
|
ContentsJump to: |
Function ManipulationTopics: |
See AlsoRelated pages:
|