mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-07 08:22:21 +02:00
Find polyfill
This commit is contained in:
parent
7e5ab3aafc
commit
b947ef17a7
|
@ -79,4 +79,29 @@ if (!Array.from) {
|
||||||
return A;
|
return A;
|
||||||
};
|
};
|
||||||
}());
|
}());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reference: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/find
|
||||||
|
if (!Array.prototype.find) {
|
||||||
|
Array.prototype.find = function(predicate) {
|
||||||
|
'use strict';
|
||||||
|
if (this == null) {
|
||||||
|
throw new TypeError('Array.prototype.find called on null or undefined');
|
||||||
|
}
|
||||||
|
if (typeof predicate !== 'function') {
|
||||||
|
throw new TypeError('predicate must be a function');
|
||||||
|
}
|
||||||
|
var list = Object(this);
|
||||||
|
var length = list.length >>> 0;
|
||||||
|
var thisArg = arguments[1];
|
||||||
|
var value;
|
||||||
|
|
||||||
|
for (var i = 0; i < length; i++) {
|
||||||
|
value = list[i];
|
||||||
|
if (predicate.call(thisArg, value, i, list)) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
}
|
}
|
Loading…
Reference in a new issue