foreach , , . , :
Array.prototype.x = 3;
var test = [1];
for (var key in test) {
console.log(key);
}
... 0, x, x [], []. , foreach, :
Array.prototype.x = 3;
var test = [1];
for (var key in test) {
if (test.hasOwnProperty(key)) {
console.log(key);
}
}
, , , . :
(function () {
function find(predicate) {
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), length = list.length >>> 0, thisArg = arguments[1], value, i;
for (i = 0; i < length; i++) {
value = list[i];
if (predicate.call(thisArg, value, i, list)) {
return value;
}
}
return undefined;
};
if (!Array.prototype.find) {
if (Object.defineProperty) {
Object.defineProperty(Array.prototype, 'find', {value: find, enumerable: false});
} else {
Array.prototype.find = find;
}
}
} ());
Array.prototype.find, , Object.defineProperty, , . , , .hasOwnProperty(), foreach. ( Array.prototype.find() ECMAScript 6, Object.defineProperty() ECMAScript 5.1, Object.prototype.hasOwnProperty() - ECMAScript 3. ES5.1 2011 , , - , Opera IE, ES6 .find(), Object.defineProperty.