当前位置:网站首页>Encapsulation manuelle d'un foreach et d'une carte
Encapsulation manuelle d'un foreach et d'une carte
2022-06-12 03:58:00 【Dossier d'auto - culture des déchets】
Encapsulation manuelle d'une méthode de tableau:forEach
function myForEach(arr,callback){
for(let i=0;i<arr.length;i++){
callback(arr[i],i);
}
}
myForEach([1,2,3],function(ele,index){
console.log(ele,index)
})
Montage du prototype
Array.prototype.myForEach = function(callback) {
for (var i = 0; i < this.length; i++) {
//Le premier argument passé lors de l'encapsulation est la valeur,Le deuxième argument est index
callback(this[i], i);
}
};
[1, 2, 3].myForEach((ele, index) => console.log(ele, index));
Emballage manuelmap
function myMap(arr, callback) {
let result = [];
for (let i = 0; i < arr.length; i++) {
result.push(callback(arr[i], i));
}
return result;
}
let res = myMap([1, 2, 3], function(ele, index) {
// console.log(ele,index)
return ele;
});
Montage du prototype
Array.prototype.myMap = function(callback) {
let result = [];
for (let i = 0; i < this.length; i++) {
result.push(callback(this[i], i));
}
return result;
};
let res= [1,2,3].myMap((ele)=>ele*2)
边栏推荐
- UI consistency design of products
- Mosaïque d'images basée sur la matrice de transformation
- How to modify the result name of MySQL query result 1 and result 2
- Mysql/oracle takes the unique time as the boundary, and the sum is less than or equal to this time, and greater than this time
- Functions (arguments, formal parameters, bubbling)
- Sed command
- Data flow diagram of Flink
- 根據變換矩陣進行圖像拼接
- 【FPGA+GPS接收器】基于FPGA的双频GPS接收器详细设计介绍
- Is it safe for Guojin Securities Commission Jinbao to open an account? How should we choose securities companies?
猜你喜欢

Naive Bayes classification of scikit learn

魏武帝 太祖知不可匡正,遂不复献言

Community Conference | the mosn community will release version 1.0 and promote the evolution of the next generation architecture

Solution to missing in unity script

【C语言】程序的内存四区模型

The memory four area model of C language program

怎样拥有心灵的平和?获得一颗全新的心灵

智能面板WiFi聯動技術,ESP32無線芯片模組,物聯網WiFi通信應用

How do I extract files from the software?

如何修改mysql 查询出来的结果名称 结果1,结果2
随机推荐
Centernet2 practice: take you through the training of custom datasets with centernet2
Solution to missing in unity script
Smart panel WiFi linkage technology, esp32 wireless chip module, Internet of things WiFi communication application
[software tool] [original] tutorial on using VOC dataset class alias batch modification tool
无线物联网WiFi模块方案,ESP32-S3芯片技术,助力设备智能化
[MySQL] MySQL installation
R语言plotly可视化:可视化回归模型实际值和回归预测值的散点图分析回归模型的预测效能、区分训练集和测试集、一个好的模型大部分的散点在对角线附近、添加边缘直方图以快速诊断模型可能存在的任何预测偏差
【C语言】变量本质分析
[Clickhouse column] user initialization of new library role
Kotlin协程协程作用域,CoroutineScope MainScope GlobalScope viewModelScope lifecycleScope 分别代表什么
Will subsequent versions support code block search highlighting
[untitled]
3768 string pruning (double pointer)
智能面板WiFi联动技术,ESP32无线芯片模组,物联网WiFi通信应用
Three ways for ORALCE to process column to row conversion and finally generate table style data
[fpga+fft] design and implementation of FFT frequency meter based on FPGA
Simple database connection example
Recommended system cleaning tools, cocktail Download
R语言plotly可视化:使用plotly可视化简单线性回归模型的回归线(simple regression model linear regression plots)
How to modify the result name of MySQL query result 1 and result 2