-1
 new SomeClass().get(function(resultvariable){
    console.log(resultvariable); // works
 });

How could the "resultvariable" be used outside of the class function ?

aknd
  • 749
  • 2
  • 6
  • 24

1 Answers1

1

Declare a global variable outside of the class. Then assign the value of resultvariable to that global variable.

var globalVariable;
new SomeClass().get(function(resultvariable){
   console.log(resultvariable); // works
   globalVariable = resultvariable;
});
Eddi
  • 782
  • 1
  • 7
  • 20
  • That usually won't work. The name of the function and the way it takes a callback argument very strongly implies that it is asynchronous. Most of the time, the global won't have a value assigned to it soon enough to achieve the objective. – Quentin Jul 15 '16 at 10:55
  • Even if it's asynchronous it will get assigned, just not after the call on `.get()`. – Eddi Jul 15 '16 at 10:57
  • … that's what I said. – Quentin Jul 15 '16 at 10:58