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 @ 2022-08-24 23:16  盘思动  阅读(18)  评论(0编辑  收藏  举报