JSFiddle - React, Tailwind, and code Playground

by Farzad YZ

JavaScript

// add(1)(2)(3)(4)(5).result(); // 15

console.clear();

function partial(fn /*, args...*/) {
  // A reference to the Array#slice method.
  var slice = Array.prototype.slice;
  // Convert arguments object to an array, removing the first argument.
  var args = slice.call(arguments, 1);
  
  console.log(args);

  return function() {
    // Invoke the originally-specified function, passing in all originally-
    // specified arguments, followed by any just-specified arguments.
    return fn.apply(this, args.concat(slice.call(arguments, 0)));
  };
}

function add(num) {
	return partial(add);
}

console.log(add(1)(2)(3));