mirror of
https://github.com/flynx/types.js.git
synced 2025-10-28 10:00:08 +00:00
removed .before(..) / .after(..) from functions...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
1c18b2eb1b
commit
991e30f52e
68
Function.js
68
Function.js
@ -1,68 +0,0 @@
|
||||
/**********************************************************************
|
||||
*
|
||||
*
|
||||
*
|
||||
**********************************************/ /* c8 ignore next 2 */
|
||||
((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define)
|
||||
(function(require){ var module={} // make module AMD/node compatible...
|
||||
/*********************************************************************/
|
||||
|
||||
var object = require('ig-object')
|
||||
|
||||
|
||||
/*********************************************************************/
|
||||
|
||||
var FunctionProtoMixin =
|
||||
module.FunctionProtoMixin =
|
||||
object.Mixin('FunctionProtoMixin', 'soft', {
|
||||
// NOTE: this is more usefull to define new functions for later reuse
|
||||
// rather than one-time "modding", for example, calling this on
|
||||
// instance methods will lose context:
|
||||
// ;[1,3,2]
|
||||
// .sort
|
||||
// .post(function(res){
|
||||
// return res.pop() })
|
||||
//
|
||||
// a better way to do this:
|
||||
// ;[1,3,2]
|
||||
// .sort()
|
||||
// .pop()
|
||||
//
|
||||
// and a better way to use this is:
|
||||
// Array.prototype.greatest =
|
||||
// Array.prototype
|
||||
// .sort
|
||||
// .post(function(res){
|
||||
// return res.pop() })
|
||||
//
|
||||
// XXX this more complicated and less clear than:
|
||||
// Array.prototype.greatest =
|
||||
// function(){
|
||||
// return this
|
||||
// .sort()
|
||||
// .pop() }
|
||||
// ...are there cases when this is actually needed???
|
||||
// XXX add doc...
|
||||
before: function(func){
|
||||
var that = this
|
||||
return function(){
|
||||
var res = func.call(this, ...arguments)
|
||||
res = res === undefined ?
|
||||
that
|
||||
: res
|
||||
return res.call(this, ...arguments) }},
|
||||
after: function(func){
|
||||
var that = this
|
||||
return function(){
|
||||
return func.call(this,
|
||||
that.call(this,
|
||||
...arguments),
|
||||
...arguments) }},
|
||||
})
|
||||
|
||||
FunctionProtoMixin(Function.prototype)
|
||||
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* vim:set ts=4 sw=4 : */ return module })
|
||||
31
README.md
31
README.md
@ -13,9 +13,6 @@ A library of JavaScript type extensions, types and type utilities.
|
||||
- [`Object.matchPartial(..)`](#objectmatchpartial)
|
||||
- [`<object>.run(..)`](#objectrun)
|
||||
- [`Object.sort(..)`](#objectsort)
|
||||
- [`Function`](#function)
|
||||
- [`<function>.before(..)` (EXPERIMENTAL)](#functionbefore-experimental)
|
||||
- [`<function>.after(..)` (EXPERIMENTAL)](#functionafter-experimental)
|
||||
- [`Array`](#array)
|
||||
- [`<array>.first(..)` / `<array>.last(..)`](#arrayfirst--arraylast)
|
||||
- [`<array>.rol(..)`](#arrayrol)
|
||||
@ -327,34 +324,6 @@ Object.keys(Object.sort(o, ['x', 'a', '100']))
|
||||
```
|
||||
|
||||
|
||||
## `Function`
|
||||
|
||||
```javascript
|
||||
require('ig-types/Function')
|
||||
```
|
||||
|
||||
### `<function>.before(..)` (EXPERIMENTAL)
|
||||
|
||||
```bnf
|
||||
<function>.before(<func>)
|
||||
-> <function>
|
||||
|
||||
<func>(...args)
|
||||
-> <res>
|
||||
```
|
||||
|
||||
### `<function>.after(..)` (EXPERIMENTAL)
|
||||
|
||||
```bnf
|
||||
<function>.after(<func>)
|
||||
-> <function>
|
||||
|
||||
<func>(<res>, ...args)
|
||||
-> <res>
|
||||
```
|
||||
|
||||
|
||||
|
||||
## `Array`
|
||||
|
||||
```javascript
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user