I have a function with X arguments. I was curious if functions will accept an object which contains the args and still function correctly.
Example:
var x = 0;
var y = 0;
var z = "test";
someFunction(x,y,z);
vs
var obj = new Object();
obj.x = 0;
obj.y = 0;
obj.Z = "test";
somefunction(obj);
vs.
var obj = new Array();
obj.push(0);
obj.push(0);
obj.push("test");
somefunction(obj);
I know you could program it to handle it, but i was curious if functions would be able to accept args in different formats as long as they were all there.
Edit:
I seem to get a syntax error of sorts when collecting objects together. What do i mean? I mean i have somefunction which accepts some args, including callbacks….. so when trying to write it up, and put all the args/callbackks in an Array to do somefunction.apply(objArray), it errors on adding the items into the set. The way i did it was:
x = new Array();
x = [url,
function(){
displayFile(url, 'image', null, ft_id, null, null, null, null, !MA.isiOS());
},
function(e){
if(DEBUG) console.log('Error creating gallery thumbnail');
alert('There was a problem creating a thumbnail');
MA.hideMessage();
}
];
newArray.push(x);
it seems to mess up on the x definition set up. Does this approach not like setting up callbacks like this?
It will if
objis the Array version, and you call it usingFunction.prototype.apply.The arguments will be passed as individuals