JSFiddle - React, Tailwind, and code Playground
JavaScript
Array = function() {
alert('I\'m Hijacked! Oh no');
};
//Sorry, D.B. says you can't modify any code above this point.
/**
* Add this as a function on the built-in Array object!
*/
var coolCustomFunction = function() {
alert('I have ' + this.length + ' elements! Cool!');
};
Array.prototype.coolCustomFunction = coolCustomFunction;//Modifies hijacked array, not original array. This makes D.B. sad :(
//Your code to add coolCustomFunction to the original Array object here!
//Your very own D.B.-approved unit test:
var testCoolCustomFunction = function() {
try {
var myArray2 = new Array();
myArray2.coolCustomFunction();
} catch (e) {
alert('Fail!');
}
};
testCoolCustomFunction();