javascript - Scope issue with passing function as parameter -


After instantating my class, I call myClass.testScope () The other function that calls inside the orbit. But, when I pass the function as a parameter, then I lose the scope and testScopeFromPassedParam to data1 results in the error Uncaught TypeError : Object [object global] has no way 'testScopeFromPassedParam'

Can someone help with the best way to handle it?

  Classes McCallus Test: () - & gt; @testScope () testScope: () - & gt; Console.log 'strategy' testScopeParam: () - & gt; Console.log 'No Working' Data 1: (CB) - & gt; # Shoot. Error. @testScopeFromPassedParam () setTimeout (-> CB '1'), 1000 data2: (CB) - & gt; SetTimeout (-> CB '2'), 3000 load data: () - & gt; GetDeferred = (some functions) - & gt; Suspended = $ Inactive () some functions (data) - & gt; Console.log data deferred.resolve () deferred datafunction = [@ data1 @ data2] arrayOfPromises = [] arrayOfPromises.push getDeferred (someFunction) $ for some functions in the datafunction. When .apply (zero, arrayOfPromises) .done () = & gt; Warning 'back' myClass = new MyClass () myClass.testScope () myClass.loadData ()    

This [variable] is not scope, that is what is lost here. You will need to bind the complex to your object, in coffeescript, you can use it for:

  data1: (cb) = & gt; @TestScopeFarmPadPem () a ?? |   

BTW, you should actually do the function on data (or just use somefunction deferred.resolve) )

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

jsp - Google line chart x-axis shrinks on transition -

java - Reaching JTextField in a DocumentListener -