if (typeof Array.prototype.filter === 'undefined') {
Array.prototype.filter = function (fn, scope) {
var result = [];
for (var i = 0; i < this.length; i++) {
if (fn.call(scope, this[i], i, this)) {
result.push(this[i]);
}
}
return result;
};
}
Array.prototype.filter = function (fn, scope) {
var result = [];
for (var i = 0; i < this.length; i++) {
if (fn.call(scope, this[i], i, this)) {
result.push(this[i]);
}
}
return result;
};
}
var array = [1, 2, 3, 4];
alert(array.filter(function (n) {return n > 2;})); // [3, 4]
alert(array.filter(function (n) {return n > 2;})); // [3, 4]