szurubooru/client/js/util/polyfill.js
rr- a32c5d1399 client/misc: remove String.format()
...and replace them with ES6 template literals I've just learned about.
2016-05-21 00:08:43 +02:00

32 lines
792 B
JavaScript

'use strict';
// fix iterating over NodeList in Chrome and Opera
NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
// non standard
Node.prototype.prependChild = function(child) {
if (this.firstChild) {
this.insertBefore(child, this.firstChild);
} else {
this.appendChild(child);
}
};
// non standard
Promise.prototype.always = function(onResolveOrReject) {
return this.then(
onResolveOrReject,
reason => {
onResolveOrReject(reason);
throw reason;
});
};
// non standard
Number.prototype.between = function(a, b, inclusive) {
const min = Math.min(a, b);
const max = Math.max(a, b);
return inclusive ?
this >= min && this <= max :
this > min && this < max;
};