OSDN Git Service

Version 0.6.x starting.
[pettanr/clientJs.git] / 0.5.x / javascripts / ie5.js
1 /**
2  * http://d.hatena.ne.jp/ofk/20080904/1220485969
3  * @author ofk
4  */
5
6 Function.prototype.apply || (Function.prototype.apply = function (x, y) {
7         x = x || window;
8         y = y ||[];
9         x.__apply = this;
10         if (!x.__apply) x.constructor.prototype.__apply = this;
11         var r, j = y.length;
12         switch (j) {
13                 case 0: r = x.__apply(); break;
14                 case 1: r = x.__apply(y[0]); break;
15                 case 2: r = x.__apply(y[0], y[1]); break;
16                 case 3: r = x.__apply(y[0], y[1], y[2]); break;
17                 case 4: r = x.__apply(y[0], y[1], y[2], y[3]); break;
18                 case 5: r = x.__apply(y[0], y[1], y[2], y[3], y[4]); break;
19                 case 6: r = x.__apply(y[0], y[1], y[2], y[3], y[4], y[5]); break;
20                 case 7: r = x.__apply(y[0], y[1], y[2], y[3], y[4], y[5], y[6]); break;
21                 case 8: r = x.__apply(y[0], y[1], y[2], y[3], y[4], y[5], y[6], y[7]); break;
22                 case 9: r = x.__apply(y[0], y[1], y[2], y[3], y[4], y[5], y[6], y[7], y[8]); break;
23                 default:
24                         var a = [];
25                         for (var i = 0; i < j; ++i)
26                                 a[i] = 'y[' + i + ']';
27                         r = eval('x.__apply(' + a.join(',') + ')');
28                         break;
29         }
30         delete x.__apply ? x.__apply : x.constructor.prototype.__apply;
31         return r;
32 });
33 Function.prototype.call || (Function.prototype.call = function () {
34         var a = arguments, x = a[0], y = [];
35         for (var i = 1, j = a.length; i < j; ++i)
36                 y[i - 1] = a[i]
37         return this.apply(x, y);
38 });
39 Array.prototype.pop || (Array.prototype.pop = function () {
40         var r = this[this.length - 1];
41         --this.length;
42         return r;
43 });
44 Array.prototype.push || (Array.prototype.push = function () {
45         for (var a = arguments, i = 0, j = a.length, l = this.length; i < j; ++i)
46                 this[l + i] = a[i];
47         return this.length;
48 });
49 Array.prototype.shift || (Array.prototype.shift = function () {
50         var r = this[0];
51         for(var i = 1, j = this.length; i < j; ++i)
52                 this[i - 1] = this[i];
53         --this.length;
54         return r;
55 });
56 Array.prototype.unshift || (Array.prototype.unshift = function () {
57         var a = arguments, l = a.length, j = this.length += l - 1;
58         for (var i = j; i >= l; --i)
59                 this[i] = this[i - l];
60         for (var i = 0; i < l; ++i)
61                 this[i] = a[i];
62         return j;
63 });
64 Array.prototype.splice || (Array.prototype.splice = function (x, y) {
65         var a = arguments, s = a.length - 2 - y, r = this.slice(x, x + y);
66         if (s > 0) {
67                 for (var i = this.length - 1, j = x + y; i >= j; --i)
68                         this[i + s] = this[i];
69         }
70         else if (s < 0) {
71                 for (var i = x + y, j = this.length; i < j; ++i)
72                         this[i + s] = this[i];
73                 this.length += s;
74         }
75         for (var i = 2, j = a.length; i < j; ++i)
76                 this[i - 2 + x] = a[i];
77         return r;
78 });