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.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.
captainbosnia
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. 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?