Why is the callwhy is the slice method only a method of an Array instance? The reason why I ask is because if you want to use it for the arguments property of function object, or a string, or an object, or a number instance, you are forced to use Array.prototype.slice.call(). And by doing that, you can pass in any type of object instance (Array, Number, String, Object) into it. So why not just default it as a method of all object instances built into the language?
In other words, instead of doing this:
Code:
function Core(){
var obj = {a : 'a', b : 'b'};
var num = 1;
var string = 'aff';
console.log(typeof arguments);//Object
console.log(arguments instanceof Array);//false
var args1 = Array.prototype.slice.call(arguments);
console.log(args1);
var args2 = Array.prototype.slice.call(obj);
console.log(args2);
var args3 = Array.prototype.slice.call(num);
console.log(args3);
var args4 = Array.prototype.slice.call(string);
console.log(args4);
Core('dom','event','ajax');
Why not just be able to do this:
Code:
function Core(){
var obj = {a : 'a', b : 'b'};
var num = 1;
var string = 'aff';
var args = arguments.slice(0);
var args2 = obj.slice(0);
var args3 = num.slice(0);
var args4 = string.slice(0);
//right now none of the above would work but it's more convenient than using the call alternative.
}
Core('dom','event','ajax');
Why did the designers of the javascript scripting language make this decision?
Thanks for response.