-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Akin C edited this page Aug 13, 2017
·
15 revisions
Welcome to the block-local-function-declarations- wiki!
In Javascript, it should be possible to redefine a function whithin a another function. It is important to know that the new defined function should only be usable within the scope of that function which contains the new definition. For a better understanding an example shall follow:
function outerFunction()
{
return "Outer function";
}
function anotherFunction()
{
//Redefining
function outerFunction()
{
return "Redefined function";
}
console.log(outerFunction());
}
anotherFunction(); //Outputs "Redefined function"
console.log(outerFunction()); //Outputs "Outer function"
In addition, redefining a function within a block(e.g. within a if statement) should not work like expected in other languages, because Javascript does not support block scoping (NOT COMPLETELY TRUE).
A solution to the example above could be like as follows:
STILL IN WORK!!
This knowledge was gained:
Effective JavaScript "68 Specific Ways to Harness the Power of JavaScript" by David Herman