Get started with es5-shim CDN
MIT licensed
The ES5-shim library provides polyfills for ES5 features in older browsers, enabling their usage without upgrading to a newer version.
Tags:- shim
- es5
- es5 shim
- javascript
- ecmascript
- polyfill
Stable version
Copied!
How to start using es5-shim CDN
<!DOCTYPE html>
<html>
<head>
<title>Get started with es5-shim CDN - cdnhub.io</title>
<script src="https://cdn.cdnhub.io/es5-shim/4.6.7/es5-shim.min.js"></script>
</head>
<body>
<script>
// ES5-compatible version of 'bind' method for older browsers
if (!Function.prototype.bind) {
Function.prototype.bind = function(context_this) {
if (typeof this !== "function") {
throw new TypeError("Function.prototype.bind - What is trying to be bound is not a function");
}
var aArgs = Array.slice(arguments, 1),
fToBind = this,
myNewBinding = function() {
return fToBind.apply(this instanceof fToBind ? this : context_this, aArgs.concat(Array.slice(arguments)));
};
if (this.prototype && this.prototype.constructor === fToBind) {
myNewBinding.prototype = Object.create(this.prototype);
myNewBinding.prototype.constructor = myNewBinding;
}
return myNewBinding;
};
}
// ES5-compatible version of 'map' method for older browsers
if (!Array.prototype.map) {
Array.prototype.map = function(callback, thisArg) {
var T, A, i, len, results;
if (this === null) {
throw new TypeError("Array.prototype.map called on null or non-object");
}
if (typeof callback !== "function") {
throw new TypeError(callback + " is not a function");
}
len = this.length >>> 0;
results = new Array(len);
for (i = 0; i < len; i++) {
if (i in this) {
T = this[i];
results[i] = callback(T, i, this);
}
}
return results;
};
}
// ES5-compatible version of 'filter' method for older browsers
if (!Array.prototype.filter) {
Array.prototype.filter = function(callback, thisArg) {
var T, currentResult, index, length, results;
if (this === null) {
throw new TypeError("Array.prototype.filter called on null or non-object");
}
if (typeof callback !== "function") {
throw new TypeError(callback + " is not a function");
}
length = this.length >>> 0;
results = new Array(length);
currentResult = undefined;
for (index = 0; index < length; index++) {
if (this[index] !== undefined) {
T = this[index];
currentResult = callback(T, index, this);
if (currentResult !== undefined) {
results[index] = T;
}
}
}
return results;
};
}
// ES5-compatible version of 'forEach' method for older browsers
if (!Array.prototype.forEach) {
Array.prototype.forEach = function(callback, thisArg) {
var T, i, length;
if (this === null) {
throw new TypeError("Array.prototype.forEach called on null or non-object");
}
if (typeof callback !== "function") {
throw new TypeError(callback + " is not a function");
}
length = this.length >>> 0;
for (i = 0; i < length; i++) {
if (i in this) {
T = this[i];
callback(T, i, this);
}
}
};
}
// Usage example
var numbers = [1, 2, 3, 4, 5];
var squares = numbers.map(function(num) {
return num * num;
});
console.log(squares); // [1, 4, 9, 16, 25]
</script>
</body>
</html>
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
All versions
0.0.0
0.0.1
0.0.2
0.0.3
0.0.4
1.0.0
1.2.10
1.2.2
1.2.3
1.2.4
1.2.6
1.2.7
1.2.8
1.2.9
2.0.0
2.0.1
2.0.10
2.0.11
2.0.12
2.0.2
2.0.3
2.0.4
2.0.5
2.0.7
2.0.8
2.0.9
2.1.0
2.2.0
2.3.0
3.0.0
3.0.1
3.0.2
3.1.0
3.1.1
3.2.0
3.3.0
3.3.1
3.3.2
3.4.0
4.0.0
4.0.1
4.0.2
4.0.3
4.0.4
4.0.5
4.0.6
4.1.0
4.1.1
4.1.10
4.1.11
4.1.12
4.1.13
4.1.14
4.1.15
4.1.16
4.1.2
4.1.3
4.1.4
4.1.5
4.1.6
4.1.7
4.1.8
4.1.9
4.2.0
4.2.1
4.3.0
4.3.1
4.3.2
4.4.0
4.4.1
4.4.2
4.5.0
4.5.1
4.5.10
4.5.11
4.5.12
4.5.13
4.5.14
4.5.15
4.5.2
4.5.3
4.5.4
4.5.5
4.5.6
4.5.7
4.5.8
4.5.9
4.6.0
4.6.1
4.6.2
4.6.3
4.6.4
4.6.5
4.6.6
*** 4.6.7