JavaScript AngularJs: Uncaught ReferenceError: $scope is not defined in debugger mode [duplicate] angularjs uncaught referenceerror require is not defined,angularjs uncaught referenceerror

With this code:

function baz() {
  var x = "foo";

  function bar() {
    debugger;
  };
  bar();
}
baz();

I get this unexpected result:

enter image description here

When I change the code:

function baz() {
  var x = "foo";

  function bar() {
    x;
    debugger;
  };
  bar();
}

I get the expected result:

enter image description here

Also, if there is any call to eval within the inner function, I can access my variable as I want to do (doesn't matter what I pass to eval).

Meanwhile, Firefox dev tools give the expected behavior in both circumstances.

What's up with Chrome that the debugger behaves less conveniently than Firefox? I have observed this behavior for some time, up to and including Version 41.0.2272.43 beta (64-bit).

Is it that Chrome's javascript engine "flattens" the functions when it can?

Interestingly if I add a second variable that is referenced in the inner function, the x variable is still undefined.

I understand that there are often quirks with scope and variable definition when using an interactive debugger, but it seems to me that based on the language specification there ought to be a "best" solution to these quirks. So I am very curious if this is due to Chrome optimizing further than Firefox. And also whether or not these optimizations can easily be disabled during development (maybe they ought to be disabled when dev tools are open?).

Also, I can reproduce this with breakpoints as well as the debugger statement.

Answer:1

Wow, really interesting!

As others have mentioned, this seems to be related to scope, but more specifically, related to debugger scope. When injected script is evaluated in the developer tools, it seems to determine a ScopeChain, which results in some quirkiness (since it's bound to the inspector/debugger scope). A variation of what you posted is this:

(EDIT - actually, you mention this in your original question, yikes, my bad!)

function foo() {
  var x = "bat";
  var y = "man";

  function bar() {
    console.log(x); // logs "bat"

    debugger; // Attempting to access "y" throws the following
              // Uncaught ReferenceError: y is not defined
              // However, x is available in the scopeChain. Weird!
  }
  bar();
}
foo();

For the ambitious and/or curious, scope (heh) out the source to see what's going on:

https://github.com/WebKit/webkit/tree/master/Source/JavaScriptCore/inspector https://github.com/WebKit/webkit/tree/master/Source/JavaScriptCore/debugger

Answer:2

I want to pass an Id when I open a model from bootstrap. I have a table and want to click on the row to do this. I am using master-pages and I am loading the jquery and bootstrap at the end of the ...

I want to pass an Id when I open a model from bootstrap. I have a table and want to click on the row to do this. I am using master-pages and I am loading the jquery and bootstrap at the end of the ...

Having a weird issue, on Windows 10 in the screen settings on some laptops the default value (the recommended) is 125% so when opening a web page everything is to big because the page was build for ...

Having a weird issue, on Windows 10 in the screen settings on some laptops the default value (the recommended) is 125% so when opening a web page everything is to big because the page was build for ...

  1. windows screen scale
  2. windows 10 screen scale
  3. windows scale screen size
  4. windows 7 screen scale
  5. windows get screen scale
  6. windows 10 scale screen size
  7. windows 10 change screen scale
  8. windows 7 scale screen resolution
  9. windows xp scale screen
  10. windows 10 lock screen scale
  11. windows 10 adjust screen scale
  12. windows 10 full screen scale
  13. windows 10 grayscale screen
  14. windows 10 qt_auto_screen_scale_factor

Has anyone implemented sending and receiving signals with opentok-react https://github.com/aiham/opentok-react? I can't find even a simple example on how to do it in React using opentok-react.

Has anyone implemented sending and receiving signals with opentok-react https://github.com/aiham/opentok-react? I can't find even a simple example on how to do it in React using opentok-react.

i created an state in constructor, and setState in componentDidmount, when i try to render that state object to screen, it is throwing error, server im using is node API, and every other things are ...

i created an state in constructor, and setState in componentDidmount, when i try to render that state object to screen, it is throwing error, server im using is node API, and every other things are ...

  1. react state rendering
  2. react state not rendering
  3. react state change not rendering