CodeClerks

Calling a Function with Arguments



Write the reason you're deleting this FAQ

Calling a Function with Arguments

Can someone please explain how to call a function with arguments? Or, post a video of how this is done?

Comments

Please login or sign up to leave a comment

Join
captainbosnia
What do you exactly mean? If there is a function with parameters within ( ), you would simply go with funcName(parameter1, paramter2) and so on...

Example:

var func1 = function(name,lastName) {

alert("You have entered " + name + " " + lastName);
}

// You call the function this way

func1("Captain","Bosnia"); // Alerts You have entered Captain Bosnia
___________________________________________

If you are defining the arguments inside, then you can do it this way.

var func2 = function(name, lastName) {
this.name = "Captain";
this.lastName = "Bosnia";
alert(this.name + " " + this.lastName);
}

func2(); // Logs Captain Bosnia
___________________________________________

However, if you are creating a function that contains stuff that cannot be accessed from outside, then you must create a public method in order to access it.



Are you sure you want to delete this post?