title: Conditionally define functions across modern browsers? Esp Safari?
body: <p>What's the best way to conditionally define functions for popular modern browsers? </p>
  
  <p>I'm seeing Safari 12 (iOS 12.0.1 and macOS 10.14) incorrectly define conditional functions while Chrome, Firefox, Edge seem to do the right thing. Additionally, what's the spec correct behavior for a JS engine so I could report this bug to Apple if it's a bug.</p>
  
  <p>Background: We're doing this to avoid Google Analytics (gtag.js) from ever loading if a user doesn't consent to GDPR. Google's gtags.js boilerplate init code has a line <code>function gtag(){dataLayer.push(arguments);}</code> which trips Safari.</p>
  
  <p>Code below, demo at <a href="https://jsfiddle.net/mxf94wdo/1/" rel="nofollow noreferrer">JS Fiddle here</a> </p>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;Safari JS engine test&lt;/title&gt;
      &lt;script type="text/javascript"&gt;
        if (false) {
          function conditionalFunctionality() {
            alert("Doing conditional functionality");
          }
        }
        window.onload = function() {
          if (typeof conditionalFunctionality === "function") {
            alert("BAD. It's defined");
          } else {
            alert("GOOD. It's NOT defined");
          }
        }
      &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;h1&gt;Safari JS engine test&lt;/h1&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <hr>
  
  <h2>Mugshots</h2>
  
  <p><a href="https://i.stack.imgur.com/Y87Tfl.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y87Tfl.jpg" alt="iOS"></a> 
  <a href="https://i.stack.imgur.com/UdEIUl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UdEIUl.png" alt="macOS"></a></p>