2 * http://d.hatena.ne.jp/ofk/20080904/1220485969
6 Function.prototype.apply || (Function.prototype.apply = function (x, y) {
10 if (!x.__apply) x.constructor.prototype.__apply = this;
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;
25 for (var i = 0; i < j; ++i)
26 a[i] = 'y[' + i + ']';
27 r = eval('x.__apply(' + a.join(',') + ')');
30 delete x.__apply ? x.__apply : x.constructor.prototype.__apply;
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)
37 return this.apply(x, y);
39 Array.prototype.pop || (Array.prototype.pop = function () {
40 var r = this[this.length - 1];
44 Array.prototype.push || (Array.prototype.push = function () {
45 for (var a = arguments, i = 0, j = a.length, l = this.length; i < j; ++i)
49 Array.prototype.shift || (Array.prototype.shift = function () {
51 for(var i = 1, j = this.length; i < j; ++i)
52 this[i - 1] = this[i];
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)
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);
67 for (var i = this.length - 1, j = x + y; i >= j; --i)
68 this[i + s] = this[i];
71 for (var i = x + y, j = this.length; i < j; ++i)
72 this[i + s] = this[i];
75 for (var i = 2, j = a.length; i < j; ++i)
76 this[i - 2 + x] = a[i];