0

I've got a quick question about scope in methods. I'm aware of local vs. global variable scope on the general level, but what happens when a variable is declared inside a method to an object? Can the variable in one method be accessible inside another method under the same object?

RJ Stank
  • 31
  • 2
  • Local variables are local to the function in which they were declared. Methods are just functions. – Bergi Jul 15 '15 at 18:36
  • Are you looking for object properties maybe? – Bergi Jul 15 '15 at 18:36
  • If the object is declared globally and you add a _property_ to it (not a _variable_), then yes, that property is accessible anywhere the object is. – blex Jul 15 '15 at 18:36

1 Answers1

0

No. If a variable is declared in a method, its scope is that method. To be accessible in a object it must be declared in the object, outside of any one method.

depperm
  • 10,606
  • 4
  • 43
  • 67