Pass an optional argument while using the Arguments Object

Is it possible to use the argument object and still pass in a flag (Boolean)?  I need to have the flexibility of processing multiple possible arrays passed in and at the same time have an option flag passed when necessary. Is that possible and if so, how? So for an example I'd like to have the following type of functionality (there will always be at least one array passed in):
_dtmInsertStaticTags(arr1)
_dtmInsertStaticTags(arr1,arr2)
_dtmInsertStaticTags(arr1,flag)
_dtmInsertStaticTags(arr1,arr2,arr3,flag)
_dtmInsertStaticTags(arr1,arr2,arr3,arrN)
_dtmInsertStaticTags(arr1,arr2,arr3,arrN,flag)
function _dtmInsertStaticTags() {


    var sTags = [];
    for (var index = 0; index < arguments.length; index++) {
        sTags = sTags.concat(arguments[index]);
    }

    //routine to inject detokenized src values into container iframe
    var iframeTag = document.createElement("iframe");
    iframeTag.setAttribute("width", "1");
    iframeTag.setAttribute("height", "1");
    iframeTag.style.display = "none";
    iframeTag.style.border = "none";

    for (var i = 0; i < sTags.length; i++) {
        var imgTag = document.createElement("img");
        imgTag.src = sTags[i];
        iframeTag.appendChild(imgTag);
    }

    if (window.addEventListener) {
        window.addEventListener("load", function () { document.body.appendChild(iframeTag); }, false);
    } else {
        window.attachEvent("onload", function () { document.body.appendChild(iframeTag); });
    }
};

Open in new window

894359Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jan LouwerensSoftware EngineerCommented:
You could use the typeof operator to determine if each argument is an array or a boolean (the flag).

for (var index = 0; index < arguments.length; index++) 
{
   console.log(typeof arguments[index]);
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Leonidas DosasCommented:
Yes it is possible.Check this simple example.We have a a() function and via if statement we check the typeof last argument of this function.If it is Boolean then an executing code is applying.
function a(){
  
  if((typeof arguments[arguments.length-1]=='boolean')){
    console.log(arguments[arguments.length-1]);
}
}
a(3,4,true);

Open in new window

Second example:
function a(){ 
  
  if((typeof arguments[arguments.length-1]=='object')){
    console.log(arguments[arguments.length-1]);
}
}
a(3,4,[true,false,false]);

Open in new window

Third example
function a(){ 
  
  if((typeof arguments[arguments.length-1]==='object')){
    if((typeof arguments[arguments.length-1][0]==='boolean')){
    console.log(arguments[arguments.length-1]);
   }
  }
}
a(3,4,[true,false,false]);

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.