add localStorage to polyfills; slightly refactor Ox.localStorage; remove whitespace; update example
This commit is contained in:
parent
41a3eaacd4
commit
5b6f161612
3 changed files with 74 additions and 28 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
Ox.polyfill = {};
|
||||
|
||||
(function(global) {
|
||||
(function(window) {
|
||||
/*@
|
||||
Ox.polyfill.bind <f> see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind
|
||||
<script>
|
||||
|
|
@ -31,7 +31,7 @@ Ox.polyfill = {};
|
|||
this_ = this,
|
||||
ret = function() {
|
||||
return this_.apply(
|
||||
this instanceof fn ? this : that || global,
|
||||
this instanceof fn ? this : that || window,
|
||||
args.concat(Array.prototype.slice.call(arguments))
|
||||
);
|
||||
};
|
||||
|
|
@ -236,6 +236,11 @@ Ox.polyfill.lastIndexOf = function(value) {
|
|||
return ret;
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.polyfill.localStorage <o> Empty object, to be used instead of localStorage
|
||||
*/
|
||||
Ox.polyfill.localStorage = {};
|
||||
|
||||
/*@
|
||||
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; })
|
||||
|
|
@ -335,12 +340,12 @@ Ox.polyfill.trim = function() {
|
|||
return this.replace(/^\s+|\s+$/g, '');
|
||||
};
|
||||
|
||||
(function(global) {
|
||||
(function(window) {
|
||||
var key, log, object;
|
||||
for (key in Ox.polyfill) {
|
||||
object = key == 'bind' ? Function.prototype
|
||||
: key == 'isArray' ? Array
|
||||
: key == 'JSON' ? global
|
||||
: key == 'JSON' || key == 'localStorage' ? window
|
||||
: key == 'keys' ? Object
|
||||
: key == 'trim' ? String.prototype
|
||||
: Array.prototype;
|
||||
|
|
@ -351,15 +356,15 @@ Ox.polyfill.trim = function() {
|
|||
// In IE8, window.console.log is an object,
|
||||
// in IE9, window.console.log.apply is undefined
|
||||
// see http://stackoverflow.com/questions/5472938/does-ie9-support-console-log-and-is-it-a-real-function
|
||||
if (global.console) {
|
||||
if (typeof global.console.log !== 'function') {
|
||||
log = global.console.log;
|
||||
global.console.log = function() {
|
||||
if (window.console) {
|
||||
if (typeof window.console.log !== 'function') {
|
||||
log = window.console.log;
|
||||
window.console.log = function() {
|
||||
log(Array.prototype.slice.call(arguments).join(' '));
|
||||
};
|
||||
} else if (!global.console.log.apply) {
|
||||
global.console.log = Function.prototype.bind.call(
|
||||
global.console.log, global.console
|
||||
} else if (!window.console.log.apply) {
|
||||
window.console.log = Function.prototype.bind.call(
|
||||
window.console.log, window.console
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue