javascript - Scope issue with passing function as parameter -
After instantating my class, I call Can someone help with the best way to handle it? 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: BTW, you should actually do the function on 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'
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 ()
data1: (cb) = & gt; @TestScopeFarmPadPem () a ?? |
data (or just use
somefunction deferred.resolve) )
Comments
Post a Comment