title: Wechat / Weixin JavaScript Bridge (WeixinJSBridge) using WeixinJSBridgeReady event listener and function as parameter
body: <p>I am using WeixinJSBridge to modify the sharing parameters when someone shares one of my games (made with JavaScript) using Wechat (Weixin).</p>
  
  <p>The following code, which is at the end of a big JavaScript file (more than 2500 lines, around 100 KB) and outside any function or object, works like a charm and the function WECHAT_onBridgeReady is called as expected when the WeixinJSBridge is ready (using the game in Wechat / Weixin):</p>
  
  <pre><code>if (document.addEventListener)
  {
      document.addEventListener('WeixinJSBridgeReady', function() { WECHAT_onBridgeReady(); }, false);
  }
  </code></pre>
  
  <p>But the following code doesn't not (the WECHAT_onBridgeReady is never called):</p>
  
  <pre><code>if (document.addEventListener)
  {
      document.addEventListener('WeixinJSBridgeReady', WECHAT_onBridgeReady, false);
  }
  </code></pre>
  
  <p>I would like to know why there is a difference between passing the funcion as parameter (which doesn't work) and passing an encapsulated function that calls the function (which works).</p>
  
  <p>Here you can see the game (made in 2006, the code is a mess and in Spanish, but I am trying to modify it now to improve it and adapt it to modern mobile devices): <a href="http://yasminoku.tuxfamily.org/new/online/" rel="nofollow">http://yasminoku.tuxfamily.org/new/online/</a> (the JavaScript file is in <a href="http://yasminoku.tuxfamily.org/new/online/yasminoku.js" rel="nofollow">http://yasminoku.tuxfamily.org/new/online/yasminoku.js</a>)</p>
  
  <p>Both methods worked before for me in another previous game, but the JavaScript file was much tinier (around 8KB) and the code that sets the event listeners was placed in the beginning of that file. This is why I think this issue could have something to do with the time the file needs to be loaded completely and parsed by the JavaScript engine, but I am not sure.</p>
  
  <p>Does anyone know the reason, please?</p>
  
  <p>Thank you in advance.</p>
  
  <p>Cheers,
   Joan</p>