mirror of
https://github.com/flynx/types.js.git
synced 2025-10-29 02:20:07 +00:00
renamed .then(..) to .after(..) and added .before(..) -- not sure if we'll keep these, seem to be overcomplicating things...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
e962f75ed2
commit
1c18b2eb1b
25
Function.js
25
Function.js
@ -20,19 +20,38 @@ object.Mixin('FunctionProtoMixin', 'soft', {
|
||||
// instance methods will lose context:
|
||||
// ;[1,3,2]
|
||||
// .sort
|
||||
// .then(function(res){
|
||||
// .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
|
||||
// .then(function(res){
|
||||
// .post(function(res){
|
||||
// return res.pop() })
|
||||
then: function(func){
|
||||
//
|
||||
// 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,
|
||||
|
||||
30
README.md
30
README.md
@ -13,6 +13,9 @@ 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)
|
||||
@ -324,6 +327,33 @@ 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`
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user