]> git.proxmox.com Git - mirror_novnc.git/commitdiff
Add array map function for IE9.
authorJoel Martin <github@martintribe.org>
Tue, 14 Feb 2012 13:53:39 +0000 (07:53 -0600)
committerJoel Martin <github@martintribe.org>
Tue, 14 Feb 2012 13:53:39 +0000 (07:53 -0600)
include/util.js

index 687f6552de8ae7e1c812d636b5959d0834c1400b..ddc1914cda048563facd29bbe00ee5fe02cf6497 100644 (file)
@@ -33,6 +33,30 @@ Array.prototype.push32 = function (num) {
               (num      ) & 0xFF  );
 };
 
+// IE does not support map (even in IE9)
+//This prototype is provided by the Mozilla foundation and
+//is distributed under the MIT license.
+//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
+if (!Array.prototype.map)
+{
+  Array.prototype.map = function(fun /*, thisp*/)
+  {
+    var len = this.length;
+    if (typeof fun != "function")
+      throw new TypeError();
+
+    var res = new Array(len);
+    var thisp = arguments[1];
+    for (var i = 0; i < len; i++)
+    {
+      if (i in this)
+        res[i] = fun.call(thisp, this[i], i, this);
+    }
+
+    return res;
+  };
+}
+
 /* 
  * ------------------------------------------------------
  * Namespaced in Util