当前位置:网站首页>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)
边栏推荐
- 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
- [mysql][mysql 8.0 compressed package installation method]
- CA证书及密钥对应用笔记
- 顺序表与链表-----进阶
- Kinematic gauge (14) - Triangle optimal path problem
- Is there a row limit for a single MySQL table
- La mise en évidence de la recherche par blocs est - elle prise en charge dans les versions ultérieures?
- 数据库精选 60 道面试题
- PyTorch中的Sequential、ModuleList和ModuleDict用法总结
- How to modify the result name of MySQL query result 1 and result 2
猜你喜欢

How to have peace of mind? Get a new heart

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

Solution en cas de défaillance du script Unity

How do I extract files from the software?

Mongodb essence summary

Convert py file to EXE file

PostgreSQL basic introduction and deployment

Summary of sequential, modulelist, and moduledict usage in pytorch

Absolute positioning three ways to center the box
![[software tool] [original] tutorial on using VOC dataset class alias batch modification tool](/img/25/31d771c9770bb7f455f35e38672170.png)
[software tool] [original] tutorial on using VOC dataset class alias batch modification tool
随机推荐
数据库新建表,以前没问题的,今天
Evolution and practice of Unicom real-time computing platform
R语言plotly可视化:可视化回归模型实际值和回归预测值的散点图分析回归模型的预测效能、区分训练集和测试集、一个好的模型大部分的散点在对角线附近、添加边缘直方图以快速诊断模型可能存在的任何预测偏差
hash function
MongoDB精华总结
R language plot visualization: plot visualization of basic 2D histogram, custom setting of color of 2D histogram, and histogram visualization of binary distribution (basic 2D histogram)
顺序表与链表-----进阶
In 2022, don't you know the difference between arrow function and ordinary function?
Kinematic gauge (14) - Triangle optimal path problem
Concept and introduction of microservice
Hudi of data Lake (14): basic concepts of Apache Hudi
Will subsequent versions support code block search highlighting
关于 国产麒麟Qt编译报错“xxx.pri has modification time xxxx s in the futrue“ 的解决方法
Exception handling and unit testing
(idea)the file size(2.85M) exceeds configured limit(2.56M).Code insight features are not available问题
JSP implementation of bank counter business performance evaluation system
19. Optimized database query of tornado project
智能面板WiFi联动技术,ESP32无线芯片模组,物联网WiFi通信应用
怎样拥有心灵的平和?获得一颗全新的心灵
Batch automated e-mail: Vika Vige table x Tencent Qianfan scene connector has made new moves, and business communication and event marketing only need 3 steps