Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the Corialization of function by JavaScript

Shulou Source: shulou.com Published: 2022-06-01 03:45:47 09月22日 Update

This article is to share with you about how JavaScript implements the Corialization of functions. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The implementation of function Corialization / function Corialization refers to a technique that converts a function that uses multiple parameters into a series of functions that use one parameter. Function curry (fn, args) {/ / get the parameter length required by the function let length = fn.length; args = args | | []; return function () {let subArgs = args.slice (0); / / concatenate all existing parameters for (let I = 0; I)

< arguments.length; i++) { subArgs.push(arguments[i]); } // 判断参数的长度是否已经满足函数所需参数的长度 if (subArgs.length >

= length) {/ / if satisfied, execute the function return fn.apply (this, subArgs);} else {/ / if not satisfied, recursively return the Corialized function and wait for the input of the parameter return curry.call (this, fn, subArgs);}};} / / es6 implements function curry (fn,... args) {return fn.length

Tags: Function parameter Curry content more article good practical multiple technology article look knowledge Corey length recursion reference help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Microsoft Linux OPPO Reno NVidia