Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

javascript arguments ?

Featured Replies

In any function, the arguments are the data that you send to the function when you call it. If, for example, you function looked like this:

function epicFunction(foo, bar, glee) {...

your arguments would be "foo", "bar" and "glee".

 

When the function is called, data is passed to it in the brackets. To call the above function and giv it some data, you'd use a pice of code like this:

epicFunction('fubab', 12, ['singing', 'dancing']);

Now, inside our epicFunction, "foo" refers to a string containing "fubab", "bar" is the number 12 and "glee" is an array with singing and dancing.

 

On a slightly more advanced level, each function has an object associated with it called "arguments" which allows you to reference any and all arguments much like you would an array. In the above example, "foo" would be the equivalent of "arguments[0]", "bar" would be "arguments[1]" and so on. "arguments.length" will tell you how many arguments have been passed to the function. This is how things like the $.extend() method in jQuery allow you to pass any number of objects to it.

 

The arguments object has another remarkable handly property "callee", which refers to the function itself. I've seen a few coders use "arguments.callee" to create an external reference to the state of the function. If you consider the code:

function epicFunction(foo, bar, glee) {
 if (foo == "fubab") {
   arguments.callee.broken = true;
 } else {
   arguments.callee.broken = false;
 }
}

then in any other function, you can check to see whether the last value of "foo" passed to "epicFunction" was "fubab" like this:

function otherFunction() {
 if (epicFunction.broken) {
   alert("D'oh!");
 } else {
   alert("Woo Hoo!");
 }
}

 

There is another property called "caller" which will return the name of the function, but it's been depreciated of late and I've never thought of a good reason for it anyway.

 

I think that's about all there is to know.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.