Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the Corialization of function by JavaScript

2025-03-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report