0
I GOT ERROR WHEN CALL FUNCTION JS (SOLVED)
Check my code bits and go to js please read my question, how to call remove() in function2() but remove() is in the function1() : const function1 = () =>{ const remove = () =>{ ...... } } const function2 = () =>{ //my question is how to call and process remove() in here please help me } https://code.sololearn.com/W18tqk4U7kmO/?ref=app
2 Respuestas
+ 1
what you declare/define in a function belong to that function scope (closure)...
scopes are accessible from same or child scopes (of functions defined inside initial scope)
lowest level scope (accessible from anywhere) is the 'global' scope, unless you doesn't define same variable/function name in local scope
however, stuff defined in global scope belong as property of global object 'window' (in browser context), so global stuff is always accessible through window object (either by using dot notation or square brackets notation -- key is the variable/function name)... unless you doesn't override 'window' in local scope ^^
you can't access function defined in function1 from function2, unless you kind of export it to the global scope:
const f1 = () => {
const g1 = () => { /*...*/ };
window.any_name = g1;
};
const f2 = () => {
any_name();
};
more on scopes & closures:
https://developer.mozilla.org/en-US/docs/Glossary/Scope
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures
0
please check my code bit first