OSDN Git Service

Version 0.6.11, add XUI_Gesture.
[pettanr/clientJs.git] / 0.6.x / js / core / 00_builtin.js
index c491406..c15f816 100644 (file)
@@ -4,11 +4,20 @@
  */\r
 \r
 Function.prototype.apply || (Function.prototype.apply = function (x, y) {\r
+       var a, i, r, j;\r
        x = x || window;\r
-       y = y ||[];\r
+       y = y || [];\r
+       \r
+       // apply 内で apply を呼んだ場合に備える\r
+       if( x === window ){\r
+               x.__apply = void 0;\r
+       } else {\r
+               delete x.__apply ? x.__apply : x.constructor.prototype.__apply ;\r
+       };\r
+       \r
        x.__apply = this;\r
        if (!x.__apply) x.constructor.prototype.__apply = this;\r
-       var r, j = y.length;\r
+       j = y.length;\r
        switch (j) {\r
                case 0: r = x.__apply(); break;\r
                case 1: r = x.__apply(y[0]); break;\r
@@ -21,18 +30,24 @@ Function.prototype.apply || (Function.prototype.apply = function (x, y) {
                case 8: r = x.__apply(y[0], y[1], y[2], y[3], y[4], y[5], y[6], y[7]); break;\r
                case 9: r = x.__apply(y[0], y[1], y[2], y[3], y[4], y[5], y[6], y[7], y[8]); break;\r
                default:\r
-                       var a = [];\r
-                       for (var i = 0; i < j; ++i)\r
+                       a = [];\r
+                       for (i = 0; i < j; ++i)\r
                                a[i] = 'y[' + i + ']';\r
                        r = eval('x.__apply(' + a.join(',') + ')');\r
                        break;\r
-       }\r
-       delete x.__apply ? x.__apply : x.constructor.prototype.__apply;\r
+       };\r
+       // delete x.__apply ? x.__apply : x.constructor.prototype.__apply ;\r
+       // ie5\r
+       if( x === window ){\r
+               x.__apply = void 0;\r
+       } else {\r
+               delete x.__apply ? x.__apply : x.constructor.prototype.__apply ;\r
+       };\r
        return r;\r
 });\r
 Function.prototype.call || (Function.prototype.call = function () {\r
-       var a = arguments, x = a[0], y = [];\r
-       for (var i = 1, j = a.length; i < j; ++i)\r
+       var a = arguments, x = a[0], y = [], i = 1, j;\r
+       for (j = a.length; i < j; ++i)\r
                y[i - 1] = a[i]\r
        return this.apply(x, y);\r
 });\r
@@ -43,13 +58,14 @@ Array.prototype.pop || (Array.prototype.pop = function () {
        return r;\r
 });\r
 Array.prototype.push || (Array.prototype.push = function () {\r
-       for (var a = arguments, i = 0, j = a.length, l = this.length; i < j; ++i)\r
+       var a = arguments, i = 0, j = a.length, l = this.length;\r
+       for (; i < j; ++i)\r
                this[l + i] = a[i];\r
        return this.length;\r
 });\r
 Array.prototype.shift || (Array.prototype.shift = function () {\r
-       var r = this[0];\r
-       for(var i = 1, j = this.length; i < j; ++i)\r
+       var r = this[0], i = 1, j = this.length;\r
+       for( ; i < j; ++i)\r
                this[i - 1] = this[i];\r
        --this.length;\r
        return r;\r