Why are some built-in methods in JavaScript not supported by older browsers ?
For example: The Array fill() method: (browser support: chrome[v.45], I.E[v.12.0], Opera[v.32.0], etc )
Out of curiosity I decided to "reinvent the wheel" and recreate the above method:
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
Array.prototype.myFunction = function (staticValue, start, end) {
for(var i = 0; i< this.length; i++) {
if(i===start) {
for(start= i; i<end+1; i++) {
this[i] = staticValue;
};
};
if(start == undefined && end == undefined) {
this[i] = staticValue;
};
};
};
var testFruits = ["Banana", "Orange", "Apple", "Mango", 456, 48999, "power"];
var cars = ["Saab", "Volvo", "BMW"];
testFruits.myFunction("Kiwi", 1, 3);
cars.myFunction("Voom!");
document.getElementById("demo").innerHTML =
testFruits + "<br />" + "<br />" +cars;
</script>
</body>
</html>
Does this mean that by recreating some new but poorly supported built-in methods make your code completely supported by old browsers ?
My theory is YES, considering that I only used regular functions and common techniques to come up with a solution.
Older browsers are old. The people who implemented the older browsers don't go back and add new features.
If a JavaScript language feature was standardized in 2015, then a browser released in 2012 just doesn't have it because time travel is not common. It's not impossible that somebody might release an update for the old browser, but then it wouldn't be an old browser anymore.
Plain JavaScript implementations of new features are sometimes possible, and those are usually called "polyfills". Many MDN pages include such code (one example). Some language features, however, involve new syntax, and that cannot be reproduced with simple JavaScript code of course.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With