1

I have some functions assigned to a variable like:

var WEBRTC_PEER_CONNECTION     = ( window.webkitRTCPeerConnection   ||
                                   window.mozRTCPeerConnection      ||
                                   window.RTCPeerConnection         );

When I try WEBRTC_PEER_CONNECTION in the Browser's console, it gives me undefined. But, when I try the following directly, I get the function:

( window.webkitRTCPeerConnection || window.mozRTCPeerConnection || window.RTCPeerConnection );

OUTPUT:

function RTCPeerconnection() { code }

Why, is it so?

Abhi
  • 4,123
  • 6
  • 45
  • 77
  • as an aside, shouldn't you be testing for the unprefixed feature first? If you start with the prefixed versions, eventually - when RTCPeerConnection is available - your app will start spitting out obsoleted warnings until the prefixed versions go away. – x0n Jan 19 '16 at 05:04
  • Seems this is how console evaluates expressions. [Check this stack for a detailed answer](http://stackoverflow.com/questions/22844840/why-does-javascript-variable-declaration-at-console-results-in-undefined-being) – Chad Jan 19 '16 at 05:10
  • Put a breakpoint at the point in your code where you are assigning `WEBRTC_PEER_CONNECTION`, and verify it is getting set correctly. –  Jan 19 '16 at 05:23

1 Answers1

0

Ok I believe the undefined you are getting is the result of defining a variable.

Try typing just WEBRTC_PEER_CONNECTION on the console and you would get the same result.


RESULTS

jkris
  • 5,851
  • 1
  • 22
  • 30
  • WEBRTC_PEER_CONNECTION is defined in a JS file which is already available after window load, I'm not defining it in Browser console. Just trying to access it. – Abhi Jan 19 '16 at 05:05
  • Oh it that case, could it be that the variable `WEBRTC_PEER_CONNECTION` is in a closure? and you tried accessing it from the browser console? – jkris Jan 19 '16 at 05:09
  • No, it's not a closure. It's just defined as a constant (in constants.js), as given in the question. – Abhi Jan 19 '16 at 05:13
  • have you checked if `contants.js` is being loaded? starting to feel like a troubleshooter, what's the right term? – jkris Jan 19 '16 at 05:16