From 1c18b2eb1b26d26b233da2f1dc259f0714b077f8 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 21 Mar 2021 13:42:00 +0300 Subject: [PATCH] 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 --- Function.js | 25 ++++++++++++++++++++++--- README.md | 30 ++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/Function.js b/Function.js index 67086e1..e92fe6b 100644 --- a/Function.js +++ b/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, diff --git a/README.md b/README.md index 230edd2..55f49d2 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,9 @@ A library of JavaScript type extensions, types and type utilities. - [`Object.matchPartial(..)`](#objectmatchpartial) - [`.run(..)`](#objectrun) - [`Object.sort(..)`](#objectsort) + - [`Function`](#function) + - [`.before(..)` (EXPERIMENTAL)](#functionbefore-experimental) + - [`.after(..)` (EXPERIMENTAL)](#functionafter-experimental) - [`Array`](#array) - [`.first(..)` / `.last(..)`](#arrayfirst--arraylast) - [`.rol(..)`](#arrayrol) @@ -324,6 +327,33 @@ Object.keys(Object.sort(o, ['x', 'a', '100'])) ``` +## `Function` + +```javascript +require('ig-types/Function') +``` + +### `.before(..)` (EXPERIMENTAL) + +```bnf +.before() + -> + +(...args) + -> +``` + +### `.after(..)` (EXPERIMENTAL) + +```bnf +.after() + -> + +(, ...args) + -> +``` + + ## `Array`