0

While development Im often get the problem, that I don't know what the actual context of a some function-calls are.

For example in an app where Im using an special SDK (e.g. facebook.sdk) Im running often in a situation where im writing the handle scripts and passing some function-calls as a parameter for callback reasons or something.

One Example:

FB.getLoginStatus(function(response) {
   this.statusChangeCallback(response);
});

...

statusChangeCallback: function(response) {
...

Now, Im wondering, why the browser throws me errors like "this.statusChangeCallback is not a function". But as you can see in the example Im defined the function. So I know: The scope/context where js calles the function like a callback is a complete different than this code (somewhere in the sdk scripts).

Is there some way to get info about the place or the stack-trace or something. I mean some better way to comprehend the way, where the functions are called (better than just the script info within the browsers console output which is not very revealing in the manner of summarized js-files for example enter image description here ).

There must be good debugging-tools out there.

EchtFettigerKeks
  • 1,692
  • 1
  • 18
  • 33
  • 1
    `this` in javascript does not work the way you think it does: http://stackoverflow.com/questions/13441307/how-does-the-this-keyword-in-javascript-act-within-an-object-literal/13441628?s=1|3.8039#13441628 – slebetman Aug 09 '15 at 20:28
  • 4
    Every browser has good developer tools built in, you just need to know how to use them. If you're using Chrome for instance, there is [a ton of documentation](https://developer.chrome.com/devtools), including specifics on [debugging javascript](https://developer.chrome.com/devtools/docs/javascript-debugging) – James Thorpe Aug 09 '15 at 20:28
  • 1
    You could use Chrome Dev. Mode (F12). If you put `debugger;` in your code, and then run your code in a browser with Chrome DevTools, it will automatically break at that line. In the "Sources" tab, there's a pane for "Scope". That might help. – pushkin Aug 09 '15 at 20:29
  • For your specific problem, see https://stackoverflow.com/questions/20279484/how-to-access-the-correct-this-context-inside-a-callback – Bergi Aug 09 '15 at 21:12
  • JamesThorpe und @Pushkin: Could you write your comments as answers please, so I can mark them properly. – EchtFettigerKeks Aug 10 '15 at 07:32
  • @MarcM The question has been closed as a duplicate - once a question is closed, you can't add answers. If it wasn't a duplicate of a pre-existing, fairly-old-so-was-on-topic-at-the-time question, this one would probably also fall into "too broad" for Stack Overflow too now. – James Thorpe Aug 10 '15 at 07:36
  • @JamesThorpe a I see. thank you guys anyway! – EchtFettigerKeks Aug 10 '15 at 08:11

0 Answers0