-1

suppose I have declared a global variable test in some file:

var test = {
  function1: function(){
    testV = "ok";
    checkFile();
  }
}

How do I access testV in another file?

Shomz
  • 37,421
  • 4
  • 57
  • 85
Leo Li
  • 73
  • 1
  • 3
  • 10

1 Answers1

1

That variable is defined in a scope local to that function. You would need to define that variable first in the global scope, and then reference it inside this function and then inside the second function.

For more information, see "What is the scope of variables in JavaScript?"

Ryan Bigg
  • 106,965
  • 23
  • 235
  • 261
  • edited! but I dont know how to reference into the variables inside the function namespaced as function1 – Leo Li Oct 29 '17 at 04:13
  • @LeoLi your edit changes the whole concept of your question and makes this answer incorrect although it nicely answered your original question. Don't do that... you can't externally access variables defined in local scopes of a function. – Shomz Oct 29 '17 at 04:20
  • @LeoLi No problem, I said it because someone else might come with the same question, but won't find the answer because you included the answer in the question. :) Welcome to Stack Overflow! – Shomz Oct 29 '17 at 08:25