As we know we can use Array prototype methods with function arguments just like below.
function abc() {
// As 'arguments' is a array like object which don't have Array prototype functions.
Array.prototype.push.call(arguments, 30);
console.log(arguments);
}
abc(10, 20); // Output is: [10, 20, 30]
So like wise I tried to use push on DOM element classList like below which gives me an error "Cannot set property length of [object Object] which has only a getter".
var bodyClassList = document.body.classList;
Array.prototype.push.call(bodyClassList, 'myClass');
Note: I have just tried to learn concepts so that's why I used push even it has builtin add() method.
So my question is:
On which objects we can use Array.prototype methods?
Thanks in advance.
classList.add('myClass')