我正在尝试将下面的jQuery扩展转换为一个类似于扩展的原型:
$.some = function(array, cmp_bool, context) {
if (Array.prototype.some) {
return array.some(cmp_bool, context);
} else {
if (context) {
cmp_bool = $.proxy(cmp_bool, context);
}
return !!($.grep(array, cmp_bool).length)
}
};
发布于 2013-03-22 23:21:37
PrototypeJS已经在核心中内置了这一点。
数组对象类型混合了可枚举的方法--其中的some()
方法具有完全相同的参数(没有数组作为第一个参数,因为您正在对数组实例执行操作)
因此,考虑到这些
var testit = function(t){
return t < 10;
}
var myArray = [1, 2, 3, 7, 10];
您提供的jQuery扩展的调用方式如下所示
$.some(myArray,testit);
//or noConflict() mode
jQuery.some(myArray,testit);
内置的PrototypeJS方法是这样调用的
myArray.some(testit);
**可枚举方法some()
别名为此处链接的any()
方法http://api.prototypejs.org/language/Enumerable/prototype/any/
https://stackoverflow.com/questions/15563322
复制相似问题