prototype 用法

Array.prototype.phpfind = function(conditionFunc) {
    console.log('conditionFunc',conditionFunc)
	for (var i = 0; i < this.length; i++) {
        //console.log(this[i])
		if (conditionFunc(this[i])) {
			// return this[i]
			return i
		}
	}
}

var arr = [
	{name:'test1', age: 1},
	{name:'test2', age: 2},
	{name:'test3', age: 3}
]

var temp = arr.phpfind(function(item){
    return item.name == 'test2'
})

console.log(temp)




posted @   盘思动  阅读(20)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
历史上的今天:
2018-08-24 git clone 无权限
2018-08-24 小程序消息推送
2017-08-24 .gitignore 无效问题
点击右上角即可分享
微信分享提示