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)
相信坚持的力量,日复一日的习惯.