ℹ️ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0.3 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://lage.us/Javascript-Variable-Name-Function-Call.html |
| Last Crawled | 2026-04-08 04:23:30 (8 days ago) |
| First Indexed | 2020-07-18 18:44:29 (5 years ago) |
| HTTP Status Code | 200 |
| Meta Title | Variable Name Functions |
| Meta Description | Call a function using a variable. A variable with the the value of a function name can call the function using this method. |
| Meta Canonical | null |
| Boilerpipe Text | Call a function using a variable. A variable with the value of a function name can call the function using this method.
Method 1 - standard functions
/*
fcn - function name
arg - argument(s) if any
*/
function run(fcn, arg) {
return window[fcn](arg);
// can also be: return top[fcn](arg);
// can also be: return this[fcn](arg);
}
Example 1:
function callFunctionByVariable(msg) {
return msg;
}
variableFunctionName = "callFunctionByVariable";
console.log(run(variableFunctionName, "hi"));
// console prints hi
Method 2 - prototype functions
// call: String.run();
String.prototype.run = function() {
return window[this]();
}
Example 2:
Javascript
(call these functions using variables)
For example purposes, there are a list of functions which return one word. Each function is called using variable values contained in an array corresponding to the function name. This demonstrates that a function call can be made from a variable.
Using the prototype function (Method 2), each of these functions will be called using variable values.
// list of functions to be called
function a() { return "This "; }
function b() { return "sentence "; }
function c() { return "is "; }
function d() { return "created "; }
function e() { return "by "; }
function f() { return "a "; }
function g() { return "list "; }
function h() { return "of "; }
function i() { return "function "; }
function j() { return "variable "; }
function k() { return "names"; }
function l() { return "."; }
// array of String values to be used to call the functions by the same name
functionList = ["a","b","c","d","e","f","g","h","i","j","k","l"];
// loop through the array and call the functions
// using the array String variable values
for (x=0; x<functionlist.length; x++) {
document.getElementById("sentence").innerHTML += functionList[x].run();
}
HTML
(put the result here)
<div id="sentence"></div> |
| Markdown | [Lage.us](https://lage.us/)
[PHP Snippets](https://lage.us/php.html) \| [HTML Snippets](https://lage.us/html.html) \| [Javascript Snippets](https://lage.us/javascript.html) \| [CSS Snippets](https://lage.us/css.html)
# Variable Name Functions
Call a function using a variable. A variable with the value of a function name can call the function using this method.
### **Method 1 - standard functions**
```
/*
fcn - function name
arg - argument(s) if any
*/
function run(fcn, arg) {
return window[fcn](arg);
// can also be: return top[fcn](arg);
// can also be: return this[fcn](arg);
}
```
### Example 1:
```
function callFunctionByVariable(msg) {
return msg;
}
```
```
variableFunctionName = "callFunctionByVariable";
console.log(run(variableFunctionName, "hi"));
// console prints hi
```
***
### **Method 2 - prototype functions**
```
// call: String.run();
String.prototype.run = function() {
return window[this]();
}
```
### Example 2:
**Javascript** (call these functions using variables)
For example purposes, there are a list of functions which return one word. Each function is called using variable values contained in an array corresponding to the function name. This demonstrates that a function call can be made from a variable.
Using the prototype function (Method 2), each of these functions will be called using variable values.
```
// list of functions to be called
function a() { return "This "; }
function b() { return "sentence "; }
function c() { return "is "; }
function d() { return "created "; }
function e() { return "by "; }
function f() { return "a "; }
function g() { return "list "; }
function h() { return "of "; }
function i() { return "function "; }
function j() { return "variable "; }
function k() { return "names"; }
function l() { return "."; }
// array of String values to be used to call the functions by the same name
functionList = ["a","b","c","d","e","f","g","h","i","j","k","l"];
// loop through the array and call the functions
// using the array String variable values
for (x=0; x<functionlist.length; x++) {
document.getElementById("sentence").innerHTML += functionList[x].run();
}
HTML (put the result here)
<div id="sentence"></div>
```
Copyright © Lage.us Website Development \| [Disclaimer](https://lage.us/disclaimer.html) \| [Privacy Policy](https://lage.us/privacy-policy.html) \| [Terms of Use](https://lage.us/terms-of-use.html)
#### Main Menu
[PHP Snippets](https://lage.us/php.html) [HTML Snippets](https://lage.us/html.html) [Javascript Snippets](https://lage.us/javascript.html) [CSS Snippets](https://lage.us/css.html)
#### Javascript Snippets
[Change a Page's Stylesheet Using Javascript](https://lage.us/Javascript-Change-Page-Stylesheet.html) [Javascript If-Else Shortcut Ternary Operator](https://lage.us/Javascript-If-Else-Shortcut-Ternary-Operator.html) [Swap Variables in One Line of Code](https://lage.us/Javascript-swap-variables-in-one-line.html) [Javascript array\_unique (similar to PHP)](https://lage.us/Javascript-array_unique.html) [Sort a Javascript 2d Array by Any Column Value](https://lage.us/Javascript-Sort-2d-Array-by-Column.html) [Sort an HTML Table by Column Using Javascript](https://lage.us/Javascript-Sort-HTML-Table-by-Column.html) [Variable Name Functions](https://lage.us/Javascript-Variable-Name-Function-Call.html) [Accordion Menu](https://lage.us/Javascript-Accordion-Menu.html) [Replace All function using Javascript](https://lage.us/Javascript-replaceAll\(\).html) [Occurrences of Substring in String](https://lage.us/Javascript-substr-count.html) [Detect Javascript Swipe for Touch Screens and Mouse](https://lage.us/Javascript-Detect-Swipe-for-Touch-and-Mouse.html) [Get Hypotenuse Using Pythagorean](https://lage.us/Javascript-Pythagorean-Get-Hypotenuse.html) [Create an Image Zoom Window with Javascript](https://lage.us/Javascript-Image-Zoom-Window-with-Javascript.html) [Get String Between Strings with Javascript](https://lage.us/Javascript-Get-String-Between-Strings.html) [Immediately Invoke a Javascript Function](https://lage.us/Javascript-Immediately-Invoke-Function.html) [Check if String Contains Substring](https://lage.us/Javascript-String-Contains-Substring.html) [Round Numbers Accurately to Specified Place Value with Javascript](https://lage.us/Javascript-Round-Numbers-to-Specified-Place-Value.html) [Check if String Contains Substring](https://lage.us/Javascript-String-Contains-Substring.html) [Pass Javascript Variables to Another Page](https://lage.us/Javascript-Pass-Variables-to-Another-Page.html) [Split a String Into a 2-Dimensional-Array](https://lage.us/Javascript-Split-String-Into-2-d-Array.html) [Strip HTML Tags from String](https://lage.us/Javascript-Strip-HTML-Tags.html) [Remove Quotes from String](https://lage.us/Javascript-Remove-Quotes-From-String.html) [Remove Return Characters From String](https://lage.us/Javascript-Remove-Return-Characters-From-String.html) [Determine if a Javascript Variable is a Number](https://lage.us/Javascript-Determine-If-Variable-Is-Number.html) [Copy text from an input box to the clipboard](https://lage.us/Javascript-Copy-To-Clipboard.html) [Fade an Element In or Out with a Toggle](https://lage.us/Javascript-Fade-In-Or-Out-An-Elelemt.html) [Javascript Equivalent to file\_get\_contents("filename.html")](https://lage.us/Javascript-File-Get-Contents.html) [Random Shuffle Javascript Array](https://lage.us/Javascript-Random-Shuffle-Array.html) [Determine When HTML Element Comes Into Viewport While Scrolling](https://lage.us/Javascript-Determine-When-Element-Is-In-View.html) [Conditionally Load a Javascript File](https://lage.us/Javascript-Conditionally-Load-JS-File.html) [Javascript Send Form With No Target](https://lage.us/Javascript-Send-Form-With-No-Target.html) [Check for Mobile Phone](https://lage.us/Javascript-Mobile-Phone-Check.html) [Get the Date String in Milliseconds](https://lage.us/Javascript-Get_Date.html) [Javascript Equivalent to array\_unique()](https://lage.us/Javascript-array_unique.html) [Javascript Equivalent to the PHP natsort()](https://lage.us/Javascript-Equivalent-to-natsort.html) [Watch or Monitor Javascript Variables for Change](https://lage.us/Javascript-Watch-Variables-for-Change.html) [Javascript Equivalent to the PHP array\_values function](https://lage.us/Javascript-Array_Values.html) [Find if Item Exists in 2-Dimentional Javascript Array](https://lage.us/Javascript-Item-in-2d-Array-Using-indexOf.html)
#### My sites
[indoorclimbing.com](https://www.indoorclimbing.com/) [ziplinerider.com](https://www.ziplinerider.com/) |
| Readable Markdown | Call a function using a variable. A variable with the value of a function name can call the function using this method.
### **Method 1 - standard functions**
```
/*
fcn - function name
arg - argument(s) if any
*/
function run(fcn, arg) {
return window[fcn](arg);
// can also be: return top[fcn](arg);
// can also be: return this[fcn](arg);
}
```
### Example 1:
```
function callFunctionByVariable(msg) {
return msg;
}
```
```
variableFunctionName = "callFunctionByVariable";
console.log(run(variableFunctionName, "hi"));
// console prints hi
```
***
### **Method 2 - prototype functions**
```
// call: String.run();
String.prototype.run = function() {
return window[this]();
}
```
### Example 2:
**Javascript** (call these functions using variables)
For example purposes, there are a list of functions which return one word. Each function is called using variable values contained in an array corresponding to the function name. This demonstrates that a function call can be made from a variable.
Using the prototype function (Method 2), each of these functions will be called using variable values.
```
// list of functions to be called
function a() { return "This "; }
function b() { return "sentence "; }
function c() { return "is "; }
function d() { return "created "; }
function e() { return "by "; }
function f() { return "a "; }
function g() { return "list "; }
function h() { return "of "; }
function i() { return "function "; }
function j() { return "variable "; }
function k() { return "names"; }
function l() { return "."; }
// array of String values to be used to call the functions by the same name
functionList = ["a","b","c","d","e","f","g","h","i","j","k","l"];
// loop through the array and call the functions
// using the array String variable values
for (x=0; x<functionlist.length; x++) {
document.getElementById("sentence").innerHTML += functionList[x].run();
}
HTML (put the result here)
<div id="sentence"></div>
``` |
| Shard | 101 (laksa) |
| Root Hash | 5460030241653794101 |
| Unparsed URL | us,lage!/Javascript-Variable-Name-Function-Call.html s443 |