1

I have a function called setupChannel that takes "socket" as a parameter. I am using redux-thunk so setupChannel returns an anonymous function with dispatch and getState as parameters. Inside that anonymous function, the debugger says socket is undefined unless I make specific reference of socket in the function.

Here socket is undefined when I use the debugger:

export const setupChannel = socket => {
  return (dispatch, getState) => {
    debugger;
  }
}

Here socket is defined when I console.log it

export const setupChannel = socket => {
  return (dispatch, getState) => {
    console.log(socket);
  }
}

Socket is also defined when I simply call a method on it:

export const setupChannel = socket => {
  return (dispatch, getState) => {
    socket.connect();
  }
}

So my question remains, why is it undefined when I pop the debugger in or possibly when I don't reference it?

Mjuice
  • 1,288
  • 2
  • 13
  • 32
  • It depends on how you call *setupChannel*, i.e. the value you pass to *socket*, but you haven't shown that. Whether unused variables are deleted or not is moot, ECMA-262 doesn't define implementation. What environment are you using? What is *debugger*? – RobG Apr 28 '17 at 00:26
  • 1
    @RobG The [`debugger;` statement](http://www.ecma-international.org/ecma-262/6.0/#sec-debugger-statement) triggers a breakpoint – Bergi Apr 28 '17 at 00:36
  • @Bergi—yes, but what environment or IDE? I guess Chrome? – RobG Apr 28 '17 at 01:19
  • @RobG Every JS debugger that I've come across as does support it. Chrome devtools including. – Bergi Apr 28 '17 at 05:53
  • It's chrome dev tools debugger. I think it's a duplicate question. – Mjuice Apr 28 '17 at 07:10

0 Answers0