Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const _makeProxy = f => new Proxy(f, {
- get (fn, prop) {
- return U[prop] && U[prop].bind({ hold: fn });
- }
- });
- const U = {
- add: function (x) {
- return _makeProxy(
- y => (
- this.hold && (y = this.hold(y)),
- x + y
- ));
- },
- multiply: function (x) {
- return _makeProxy(
- y => (
- this.hold && (y = this.hold(y)),
- x * y
- ));
- },
- eqBy: function (f) {
- return x => _makeProxy(
- y => (
- this.hold && (y = this.hold(y)),
- f(x) === f(y)
- ));
- }
- };
- console.log(( U.multiply(3).add(4) )(2)); // 10
- console.log(( U.add(3).multiply(4).multiply(3) )(2)); // 60
- console.log(
- U
- .add(3)
- .multiply(4)
- .multiply(3)
- .eqBy(Math.abs)(60)
- (2)); // true
Add Comment
Please, Sign In to add comment