From: David Thompson Date: Sat, 21 Mar 2015 14:44:25 +0000 (-0400) Subject: 2015: live: Add Array#find polyfill. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=bd956053c376facbb521a62ed358107636004782;p=libreplanet-static.git 2015: live: Add Array#find polyfill. --- diff --git a/2015/assets/js/stream.js b/2015/assets/js/stream.js index 9b6d67fc..a910e28e 100644 --- a/2015/assets/js/stream.js +++ b/2015/assets/js/stream.js @@ -21,6 +21,29 @@ * @licend The above is the entire license notice for the JavaScript code in this page */ +if (!Array.prototype.find) { + Array.prototype.find = function(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); + 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; + }; +} + var app = {}; app.icecastUrl = "//live.fsf.org";