Ox.fallback -> Ox.polyfill
This commit is contained in:
parent
f3f54186dc
commit
7dd9169b3f
1 changed files with 53 additions and 53 deletions
|
@ -1,10 +1,10 @@
|
|||
'use strict';
|
||||
|
||||
Ox.fallback = {};
|
||||
Ox.polyfill = {};
|
||||
|
||||
(function(global) {
|
||||
/*@
|
||||
Ox.fallback.bind <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind
|
||||
Ox.polyfill.bind <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind
|
||||
<script>
|
||||
Ox.test.object = {
|
||||
get: function() {
|
||||
|
@ -19,10 +19,10 @@ Ox.fallback = {};
|
|||
'foo'
|
||||
> Ox.test.get()
|
||||
'bar'
|
||||
> Ox.fallback.bind.call(Ox.test.get, Ox.test.object)()
|
||||
> Ox.polyfill.bind.call(Ox.test.get, Ox.test.object)()
|
||||
'foo'
|
||||
@*/
|
||||
Ox.fallback.bind = function(that) {
|
||||
Ox.polyfill.bind = function(that) {
|
||||
if (typeof this !== 'function') {
|
||||
throw new TypeError();
|
||||
}
|
||||
|
@ -42,13 +42,13 @@ Ox.fallback = {};
|
|||
})(this);
|
||||
|
||||
/*@
|
||||
Ox.fallback.every <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every
|
||||
> Ox.fallback.every.call([0, 1, 2], function(v, i) { return v == i; })
|
||||
Ox.polyfill.every <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every
|
||||
> Ox.polyfill.every.call([0, 1, 2], function(v, i) { return v == i; })
|
||||
true
|
||||
> Ox.fallback.every.call([true, true, false], Ox.identity)
|
||||
> Ox.polyfill.every.call([true, true, false], Ox.identity)
|
||||
false
|
||||
@*/
|
||||
Ox.fallback.every = function(iterator, that) {
|
||||
Ox.polyfill.every = function(iterator, that) {
|
||||
if (this === void 0 || this === null || typeof iterator !== 'function') {
|
||||
throw new TypeError();
|
||||
}
|
||||
|
@ -63,11 +63,11 @@ Ox.fallback.every = function(iterator, that) {
|
|||
};
|
||||
|
||||
/*@
|
||||
Ox.fallback.filter <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/filter
|
||||
> Ox.fallback.filter.call([2, 1, 0], function(v, i) { return v == i; })
|
||||
Ox.polyfill.filter <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/filter
|
||||
> Ox.polyfill.filter.call([2, 1, 0], function(v, i) { return v == i; })
|
||||
[1]
|
||||
@*/
|
||||
Ox.fallback.filter = function(iterator, that) {
|
||||
Ox.polyfill.filter = function(iterator, that) {
|
||||
if (this === void 0 || this === null || typeof iterator !== 'function') {
|
||||
throw new TypeError();
|
||||
}
|
||||
|
@ -82,15 +82,15 @@ Ox.fallback.filter = function(iterator, that) {
|
|||
};
|
||||
|
||||
/*@
|
||||
Ox.fallback.forEach <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEach
|
||||
Ox.polyfill.forEach <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEach
|
||||
<script>
|
||||
Ox.test.array = [];
|
||||
Ox.fallback.forEach.call([1, 2, 3], function(v, i) { Ox.test.array.push([v, i])})
|
||||
Ox.polyfill.forEach.call([1, 2, 3], function(v, i) { Ox.test.array.push([v, i])})
|
||||
</script>
|
||||
> Ox.test.array
|
||||
[[1, 0], [2, 1], [3, 2]]
|
||||
@*/
|
||||
Ox.fallback.forEach = function(iterator, that) {
|
||||
Ox.polyfill.forEach = function(iterator, that) {
|
||||
if (this === void 0 || this === null || typeof iterator !== 'function') {
|
||||
throw new TypeError();
|
||||
}
|
||||
|
@ -103,13 +103,13 @@ Ox.fallback.forEach = function(iterator, that) {
|
|||
};
|
||||
|
||||
/*@
|
||||
Ox.fallback.indexOf <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
|
||||
> Ox.fallback.indexOf.call([1, 2, 3, 2, 1], 2)
|
||||
Ox.polyfill.indexOf <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
|
||||
> Ox.polyfill.indexOf.call([1, 2, 3, 2, 1], 2)
|
||||
1
|
||||
> Ox.fallback.indexOf.call([1, 2, 3, 2, 1], 4)
|
||||
> Ox.polyfill.indexOf.call([1, 2, 3, 2, 1], 4)
|
||||
-1
|
||||
@*/
|
||||
Ox.fallback.indexOf = function(value) {
|
||||
Ox.polyfill.indexOf = function(value) {
|
||||
if (this === void 0 || this === null) {
|
||||
throw new TypeError();
|
||||
}
|
||||
|
@ -124,28 +124,28 @@ Ox.fallback.indexOf = function(value) {
|
|||
};
|
||||
|
||||
/*@
|
||||
Ox.fallback.isArray <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray
|
||||
> Ox.fallback.isArray([])
|
||||
Ox.polyfill.isArray <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray
|
||||
> Ox.polyfill.isArray([])
|
||||
true
|
||||
> Ox.fallback.isArray((function() { return arguments; }()))
|
||||
> Ox.polyfill.isArray((function() { return arguments; }()))
|
||||
false
|
||||
> Ox.fallback.isArray({0: 0, length: 1})
|
||||
> Ox.polyfill.isArray({0: 0, length: 1})
|
||||
false
|
||||
@*/
|
||||
Ox.fallback.isArray = function(value) {
|
||||
Ox.polyfill.isArray = function(value) {
|
||||
return Object.prototype.toString.call(value) == '[object Array]';
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.fallback.JSON <o> see https://github.com/douglascrockford/JSON-js
|
||||
> Ox.fallback.JSON.parse('{"a": [1, 2], "b": [3, 4]}')
|
||||
Ox.polyfill.JSON <o> see https://github.com/douglascrockford/JSON-js
|
||||
> Ox.polyfill.JSON.parse('{"a": [1, 2], "b": [3, 4]}')
|
||||
{a: [1, 2], b: [3, 4]}
|
||||
> Ox.fallback.JSON.stringify([(function(){ return arguments; }()), false, null, 0, Infinity, NaN, / /, void 0])
|
||||
> Ox.polyfill.JSON.stringify([(function(){ return arguments; }()), false, null, 0, Infinity, NaN, / /, void 0])
|
||||
'[{},false,null,0,null,null,{},null]'
|
||||
> Ox.fallback.JSON.stringify(new Date()).length
|
||||
> Ox.polyfill.JSON.stringify(new Date()).length
|
||||
24
|
||||
@*/
|
||||
Ox.fallback.JSON = (function() {
|
||||
Ox.polyfill.JSON = (function() {
|
||||
var replace = {
|
||||
'"': '\\"',
|
||||
'\b': '\\b',
|
||||
|
@ -198,11 +198,11 @@ Ox.fallback.JSON = (function() {
|
|||
}());
|
||||
|
||||
/*@
|
||||
Ox.fallback.keys <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/keys
|
||||
> Ox.fallback.keys({a: 1, b: 2, c: 3})
|
||||
Ox.polyfill.keys <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/keys
|
||||
> Ox.polyfill.keys({a: 1, b: 2, c: 3})
|
||||
['a', 'b', 'c']
|
||||
@*/
|
||||
Ox.fallback.keys = function(object) {
|
||||
Ox.polyfill.keys = function(object) {
|
||||
if (object !== Object(object)) {
|
||||
throw new TypeError();
|
||||
}
|
||||
|
@ -216,13 +216,13 @@ Ox.fallback.keys = function(object) {
|
|||
};
|
||||
|
||||
/*@
|
||||
Ox.fallback.lastIndexOf <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/lastIndexOf
|
||||
> Ox.fallback.lastIndexOf.call([1, 2, 3, 2, 1], 2)
|
||||
Ox.polyfill.lastIndexOf <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/lastIndexOf
|
||||
> Ox.polyfill.lastIndexOf.call([1, 2, 3, 2, 1], 2)
|
||||
3
|
||||
> Ox.fallback.lastIndexOf.call([1, 2, 3, 2, 1], 4)
|
||||
> Ox.polyfill.lastIndexOf.call([1, 2, 3, 2, 1], 4)
|
||||
-1
|
||||
@*/
|
||||
Ox.fallback.lastIndexOf = function(value) {
|
||||
Ox.polyfill.lastIndexOf = function(value) {
|
||||
if (this === void 0 || this === null) {
|
||||
throw new TypeError();
|
||||
}
|
||||
|
@ -237,11 +237,11 @@ Ox.fallback.lastIndexOf = function(value) {
|
|||
};
|
||||
|
||||
/*@
|
||||
Ox.fallback.map <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/map
|
||||
> Ox.fallback.map.call([2, 1, 0], function(v, i) { return v == i; })
|
||||
Ox.polyfill.map <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/map
|
||||
> Ox.polyfill.map.call([2, 1, 0], function(v, i) { return v == i; })
|
||||
[false, true, false]
|
||||
@*/
|
||||
Ox.fallback.map = function(iterator, that) {
|
||||
Ox.polyfill.map = function(iterator, that) {
|
||||
if (this === void 0 || this === null || typeof iterator !== 'function') {
|
||||
throw new TypeError();
|
||||
}
|
||||
|
@ -256,11 +256,11 @@ Ox.fallback.map = function(iterator, that) {
|
|||
};
|
||||
|
||||
/*@
|
||||
Ox.fallback.reduce <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/reduce
|
||||
> Ox.fallback.reduce.call([1, 2, 3], function(p, c, i) { return p + c + i; }, 1)
|
||||
Ox.polyfill.reduce <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/reduce
|
||||
> Ox.polyfill.reduce.call([1, 2, 3], function(p, c, i) { return p + c + i; }, 1)
|
||||
10
|
||||
@*/
|
||||
Ox.fallback.reduce = function(iterator, ret) {
|
||||
Ox.polyfill.reduce = function(iterator, ret) {
|
||||
if (this === void 0 || this === null || typeof iterator !== 'function') {
|
||||
throw new TypeError();
|
||||
}
|
||||
|
@ -281,11 +281,11 @@ Ox.fallback.reduce = function(iterator, ret) {
|
|||
};
|
||||
|
||||
/*@
|
||||
Ox.fallback.reduceRight <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/reduceRight
|
||||
> Ox.fallback.reduceRight.call([1, 2, 3], function(p, c, i) { return p + c + i; }, 1)
|
||||
Ox.polyfill.reduceRight <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/reduceRight
|
||||
> Ox.polyfill.reduceRight.call([1, 2, 3], function(p, c, i) { return p + c + i; }, 1)
|
||||
10
|
||||
@*/
|
||||
Ox.fallback.reduceRight = function(iterator, ret) {
|
||||
Ox.polyfill.reduceRight = function(iterator, ret) {
|
||||
if (this === void 0 || this === null || typeof iterator !== 'function') {
|
||||
throw new TypeError();
|
||||
}
|
||||
|
@ -306,13 +306,13 @@ Ox.fallback.reduceRight = function(iterator, ret) {
|
|||
};
|
||||
|
||||
/*@
|
||||
Ox.fallback.some <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
|
||||
> Ox.fallback.some.call([2, 1, 0], function(v, i) { return v == i; })
|
||||
Ox.polyfill.some <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
|
||||
> Ox.polyfill.some.call([2, 1, 0], function(v, i) { return v == i; })
|
||||
true
|
||||
> Ox.fallback.some.call([false, false, false], Ox.identity)
|
||||
> Ox.polyfill.some.call([false, false, false], Ox.identity)
|
||||
false
|
||||
@*/
|
||||
Ox.fallback.some = function(iterator, that) {
|
||||
Ox.polyfill.some = function(iterator, that) {
|
||||
if (this === void 0 || this === null || typeof iterator !== 'function') {
|
||||
throw new TypeError();
|
||||
}
|
||||
|
@ -327,17 +327,17 @@ Ox.fallback.some = function(iterator, that) {
|
|||
};
|
||||
|
||||
/*@
|
||||
Ox.fallback.trim <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/Trim
|
||||
> Ox.fallback.trim.call(' foo ')
|
||||
Ox.polyfill.trim <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/Trim
|
||||
> Ox.polyfill.trim.call(' foo ')
|
||||
'foo'
|
||||
@*/
|
||||
Ox.fallback.trim = function() {
|
||||
Ox.polyfill.trim = function() {
|
||||
return this.replace(/^\s+|\s+$/g, '');
|
||||
};
|
||||
|
||||
(function(global) {
|
||||
var key, log, object;
|
||||
for (key in Ox.fallback) {
|
||||
for (key in Ox.polyfill) {
|
||||
object = key == 'bind' ? Function.prototype
|
||||
: key == 'isArray' ? Array
|
||||
: key == 'JSON' ? global
|
||||
|
@ -345,7 +345,7 @@ Ox.fallback.trim = function() {
|
|||
: key == 'trim' ? String.prototype
|
||||
: Array.prototype;
|
||||
if (!object[key]) {
|
||||
object[key] = Ox.fallback[key];
|
||||
object[key] = Ox.polyfill[key];
|
||||
}
|
||||
}
|
||||
// In IE8, window.console.log is an object,
|
Loading…
Reference in a new issue