-
Notifications
You must be signed in to change notification settings - Fork 0
Home
This repository is part of a larger project!
The Javascript object arguments should work function-scoped oriented. Here follows an example:
function g()
{
function f()
{
for(var i = 0; i < arguments.length; i++)
{
console.log(arguments[i]);
}
}
//Calling f
f();
}
//Outputs: undefined
g(1,2,3,4,5);
By analysing the listing above, it should be said that arguments in the nested function f works only for this function. This should be the reason why g(1,2,3,4,5) outputs undefined . To output the arguments (1,2,3,4,5) with the object arguments the code could look like as follows:
function g()
{
//Object "arguments" here belongs to the function g()
for(var i = 0; i < arguments.length; i++)
{
console.log(arguments[i]);
}
function f()
{
//Object arguments here belongs to the function f()
for(var i = 0; i < arguments.length; i++)
{
console.log(arguments[i]);
}
}
f();
}
//Outputs: 1,2,3,4 and 5
g(1,2,3,4,5);
📕 It should be possible to give the arguments of g to the function f by saving g's object arguments to a variable as the following example should show:
function g()
{
var parameters = arguments;
function f()
{
for(var i = 0; i < parameters.length; i++)
{
console.log(parameters[i]);
}
}
f();
}
//Outputs: 1,2,3,4 and 5
g(1,2,3,4,5);
Again, the last listing should work, because Javascript should be function-scoped.
The user interaction part could look like the content as seen below by starting "index.html" in a web browser and interacting with its features.
🅱️ utton "<<" should change to the previous image🅱️ utton ">>" should change to the next image
To use the project just download the files and execute "index.html". Note that all files(folder "wiki_images" excluded) should be placed in the same folder so that the functionality of the code is guaranteed.
This knowledge was gained:
Effective JavaScript "68 Specific Ways to Harness the Power of JavaScript" by David Herman