afterfn
Execute a function after given function.
afterfn
Simply executes after the function is called.
afterfn.return
Allows manipulation of return value.
Examples
{ return x * 2} // calls 'Math.abs' after 'doubleNumber'// after.return allows manipulation of return valuevar doubleNumberAbs = after var calledWith = var results = doubleNumberAbs = console // => 20console // => 20console // => 200 console // => [ 10, -10, -100 ]console // => [ 20, 20, 200 ]
var myPackage = name: 'my-package' version: 1 { // build routine } { thisversion++ } // always calls 'myPackage.build' *after* 'myPackage.bumpVersion'myPackagebuild = console // => my-package@v1myPackageconsole // => my-package@v2
Facts
afterfn
returns a new Function.afterfn
ignores return value of after functionafterfn.return
allows manipulation of return value- Original return value will be passed as the first argument to the after function.
- Original arguments will be passed as the second argument to the after function.
- Original function will be passed as the third argument to the after function.
- Original function
this
context is maintained. - Properties and prototype are inherited though function arity will not be preserved.
See Also
License
MIT