2 * @preserve Copyright 2012-2014 pettanR team.
\r
3 * https://sourceforge.jp/projects/pettanr/
\r
4 * BSD 3-Clause License
\r
8 * ビルトインオブジェクトに拡張したい10のメソッド
\r
9 * http://d.hatena.ne.jp/ofk/20080922/1222047483
\r
12 Function.prototype.apply || (Function.prototype.apply = function (x, y) {
\r
17 // apply 内で apply を呼んだ場合に備える
\r
21 if( x.constructor && x.constructor.prototype.__apply ){
\r
22 delete x.constructor.prototype.__apply;
\r
24 if( x.__apply ) delete x.__apply;
\r
28 if (!x.__apply) x.constructor.prototype.__apply = this;
\r
31 case 0: r = x.__apply(); break;
\r
32 case 1: r = x.__apply(y[0]); break;
\r
33 case 2: r = x.__apply(y[0], y[1]); break;
\r
34 case 3: r = x.__apply(y[0], y[1], y[2]); break;
\r
35 case 4: r = x.__apply(y[0], y[1], y[2], y[3]); break;
\r
36 case 5: r = x.__apply(y[0], y[1], y[2], y[3], y[4]); break;
\r
37 case 6: r = x.__apply(y[0], y[1], y[2], y[3], y[4], y[5]); break;
\r
38 case 7: r = x.__apply(y[0], y[1], y[2], y[3], y[4], y[5], y[6]); break;
\r
39 case 8: r = x.__apply(y[0], y[1], y[2], y[3], y[4], y[5], y[6], y[7]); break;
\r
40 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
43 for (i = 0; i < j; ++i)
\r
44 a[i] = 'y[' + i + ']';
\r
45 //r = eval('x.__apply(' + a.join(',') + ')');
\r
46 // closuer compiler 対策
\r
47 r = (new Function( 'x,y', 'return x.__apply(' + a.join(',') + ')' ))( x, y );
\r
54 //alert( typeof x );
\r
55 if( x.constructor && x.constructor.prototype.__apply ){
\r
56 delete x.constructor.prototype.__apply;
\r
58 if( x.__apply ) delete x.__apply;
\r
62 Function.prototype.call || (Function.prototype.call = function () {
\r
63 var a = arguments, x = a[0], y = [], i = 1, j = a.length;
\r
66 return this.apply(x, y);
\r
69 Array.prototype.pop || (Array.prototype.pop = function () {
\r
70 var r = this[this.length - 1];
\r
74 Array.prototype.push || (Array.prototype.push = function () {
\r
75 var a = arguments, i = 0, j = a.length, l = this.length;
\r
80 Array.prototype.shift || (Array.prototype.shift = function () {
\r
81 var r = this[0], i = 1, j = this.length;
\r
83 this[i - 1] = this[i];
\r
87 Array.prototype.unshift || (Array.prototype.unshift = function () {
\r
88 var a = arguments, l = a.length, j = this.length += l - 1, i = j;
\r
90 this[i] = this[i - l];
\r
91 for (i = 0; i < l; ++i)
\r
95 Array.prototype.splice || (Array.prototype.splice = function (x, y) {
\r
96 var a = arguments, s = a.length - 2 - y, r = this.slice(x, x + y),i,j;
\r
98 for (i = this.length - 1, j = x + y; i >= j; --i)
\r
99 this[i + s] = this[i];
\r
102 for (i = x + y, j = this.length; i < j; ++i)
\r
103 this[i + s] = this[i];
\r
106 for (i = 2, j = a.length; i < j; ++i)
\r
107 this[i - 2 + x] = a[i];
\r
113 * JavaScript 1.6, Array.indexOfを下位互換実装する
\r
114 * http://www.inazumatv.com/contents/archives/7965
\r
117 Array.prototype.indexOf || (Array.prototype.indexOf = function( searchElement, fromIndex ){
\r
118 var l = this.length >>> 0, i;
\r
120 if( l === 0 ) return -1;
\r
123 i = fromIndex || 0;
\r
124 i = i === -Infinity ? 0 : ( i < 0 ? -i : i ) | 0; // Math.floor
\r
125 if( l <= i ) return -1;
\r
128 for( i = 0 <= i ? i : 0 < l + i ? l + i : 0; i < l; ++i ){
\r
129 if( this[ i ] === searchElement ) return i;
\r
137 * by http://nurucom-archives.hp.infoseek.co.jp/digital/trans-uri.html
\r
140 /* 正規表現が使われているため、まだ投入しない itozyun
\r
141 window.encodeURI || (window.encodeURI = function (x) {
\r
142 return ("" + x).replace(/[^!#$&-;=?-Z_a-z~]/g, function (s) {
\r
143 var c = s.charCodeAt(0), p = "%";
\r
145 c < 16 ? "%0" + c.toString(16) :
\r
146 c < 128 ? p + c.toString(16) :
\r
147 c < 2048 ? p + (c >> 6 | 192).toString(16) + p + (c & 63 | 128).toString(16) :
\r
148 p + (c >> 12 | 224).toString(16) + p + (c >> 6 & 63 | 128).toString(16) + p + (c & 63 | 128).toString(16)
\r
153 window.encodeURIComponent || (window.encodeURIComponent = function (x) {
\r
154 return ("" + x).replace(/[^!'-*.0-9A-Z_a-z~-]/g, function (s) {
\r
155 var c = s.charCodeAt(0), p = "%";
\r
157 c < 16 ? "%0" + c.toString(16) :
\r
158 c < 128 ? p + c.toString(16) :
\r
159 c < 2048 ? p + (c >> 6 | 192).toString(16) + p + (c & 63 | 128).toString(16) :
\r
160 p + (c >> 12 | 224).toString(16) + p + (c >> 6 & 63 | 128).toString(16) + p + (c & 63 | 128).toString(16)
\r
166 window.decodeURI || (window.decodeURI = function (x) {
\r
167 return ("" + x).replace(/%(E(0%[AB]|[1-CEF]%[89AB]|D%[89])[0-9A-F]|C[2-9A-F]|D[0-9A-F])%[89AB][0-9A-F]|%[0-7][0-9A-F]/ig, function (s) {
\r
168 var c = parseInt(s.substring(1), 16);
\r
169 return String.fromCharCode(
\r
171 c < 224 ? (c & 31) << 6 | parseInt(s.substring(4), 16) & 63 :
\r
172 ((c & 15) << 6 | parseInt(s.substring(4), 16) & 63) << 6 | parseInt(s.substring(7), 16) & 63
\r
179 //window.decodeURIComponent || (window.decodeURIComponent = window.decodeURI);
\r
186 // replace(RegExp, Function)対応
\r
188 if (window.ActiveXObject ? !Number.prototype.toFixed : (!navigator.taintEnabled && !document.createElement("input").setSelectionRange))
\r
190 var g = String.prototype.replace;
\r
191 String.prototype.replace = function (x, y) {
\r
192 var s = this, z = y;
\r
194 if (y instanceof Function) {
\r
196 if (x instanceof RegExp) {
\r
198 if (x.global || /^\/.*g$/.test(x)) {
\r
200 while ((m = x.exec(s)) != null) {
\r
202 r[r.length] = s.slice(0, i);
\r
203 s = s.slice(i + m[0].length);
\r
204 r[r.length] = y.apply(null, m.concat(i, this));
\r
212 z = y.apply(null, m.concat(m.index, s));
\r
215 var i = s.indexOf(x);
\r
221 return g.call(s, x, z);
\r
226 * Safari の JavaScript の不備
\r
227 * http://nanto.asablo.jp/blog/2006/01/13/209495
\r
229 * web.paulownia.jp - JavaScriptとクロージャ
\r
230 * https://web.archive.org/web/20070526063400/http://web.paulownia.jp/script/oop/closure.html
\r
231 * MacOSX 10.3のsafariにはhasOwnPropertyが実装されていないので、独自に追加する必要があります。
\r
234 Object.prototype.hasOwnProperty || (Object.prototype.hasOwnProperty = function( p ){
\r
235 var proto = this.constructor && this.constructor.prototype,
\r
236 __p__ = proto && proto.__proto__,
\r
240 if( __p__ ) proto.__proto__ = null;
\r
244 if( proto && ( p in proto ) && proto[ p ] !== proto[ p ] ){ // proto[ p ] is NaN
\r
245 proto[ p ] = 0; // different value
\r
246 r = this[ p ] !== this[ p ]; // isNaN?
\r
247 proto[ p ] = v; // set NaN
\r
252 if( proto && p in proto && proto[ p ] === v ){
\r
253 // this と proto に同名で同値が書かれている可能性あり
\r
254 proto[ p ] = v + ' '; // different value
\r
255 r = v === this[ p ];
\r
262 if( __p__ ) proto.__proto__ = __p__;
\r
267 Object.prototype.hasOwnProperty || (Object.prototype.hasOwnProperty = function( p ){
\r
268 var proto = this.constructor && this.constructor.prototype,
\r
269 __p__ = proto && proto.__proto__,
\r
270 r = false,//!!( __p__ && ( proto.__proto__ = null ) )
\r
273 if( __p__ ) proto.__proto__ = null;
\r
274 if( this.__proto__ ){
\r
275 _pro_ = this.__proto__;
\r
276 this.__proto__ = null;
\r
279 if( p === '__proto__' ){
\r
286 if( proto && p in proto && ( proto[ p ] === v ) ^ isNaN ){ //true + false, false + true
\r
287 // this と proto に同名で同値が書かれている可能性あり
\r
288 proto[ p ] = v + ' '; // different value
\r
289 r = ( v === this[ p ] ) ^ isNaN; // true + false, false + true
\r
297 if( __p__ ) proto.__proto__ = __p__;
\r
298 if( _p_ ) this.__proto__ = _pro_;
\r