I am having a hard time understanding Static scope in Javascript. Can anyone please explain the difference between the below two functions
It works fine if I do
function sayHi(){
alert("Hi");
}
sayHi.alternate=function(){
alert("Hola");
}
sayHi();
sayHi.alternate();
But doenst work if I do
function sayHi(){
alert("Hi");
}
function sayHi.alternate(){
alert("Hola");
}
sayHi();
sayHi.alternate();
As usual Thanks
This isn’t valid javascript:
You can’t assign a property when declaring a function this way. You can only define a name to be used for the function. That’s why the other form is used when you’re assigning it to an object property or assigning to a variable.