title: How to affect a function to a variable in javascript
body: <p>I have the following two function that return promises ( if I m correct we call it promises correct me if I m wrong )</p>
  
  <p><strong>fullscreenSource</strong></p>
  
  <pre><code>function fullscreenSource(id) {
      function search(child, id) {
  
          if (child !== undefined) {
  
              if (child.id === id || child.code === id) {
                  console.log(id);
                  console.log(child.id);
                  return child.sourceFullScreen;
              } else {
                  if (child.children !== undefined &amp;&amp; child.children.length &gt; 0) {
                      for (let index = 0; index &lt; child.children.length; index++) {
                          data = undefined;
                          data = search(child.children[index], id);
                          if (data !== undefined) return data;
                      }
                  }
              }
  
          }
      }
  
      return search(camSourceRepo.getAll(), id);
  }
  </code></pre>
  
  <p><strong>normalSource</strong></p>
  
  <pre><code>function screenSource(id) {
      function search(child, id) {
  
          if (child !== undefined) {
  
              if (child.id === id || child.code === id) {
                  console.log(id);
                  console.log(child.id);
                  return child.source;
              } else {
                  if (child.children !== undefined &amp;&amp; child.children.length &gt; 0) {
                      for (let index = 0; index &lt; child.children.length; index++) {
                          data = undefined;
                          data = search(child.children[index], id);
                          if (data !== undefined) return data;
                      }
                  }
              }
  
          }
      }
  
      //console.log(camSourceRepo.getAll());
      return camSourceRepo.getAll().then(cams =&gt; {
          console.log(cams)
          return search(cams, id);
      })
  
  
  }
  </code></pre>
  
  <p>I got the idea to use them in a functional fassion . like this :</p>
  
  <pre><code>let _screenSource = screenSource(p1);
  if(div_prefix.includes("fullplayer_"))_screenSource = fullscreenSource(p1);
  
  console.log(_screenSource)
  _screenSource.then(source =&gt; {
      console.log(source);   
     });
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>trying to use the funciton reference doesn't work</p>
  
  <pre><code>let _screenSource = screenSource;
  if(div_prefix.includes("fullplayer_"))_screenSource = fullscreenSource;
  
  console.log(_screenSource)
  _screenSource(p1).then(source =&gt; {
      console.log(source);   
     });
  
  </code></pre>
  
  <p>However my <code>_screenSource</code> is undefined, Why ?</p>
  
  <p>How to affect a function dynamically to a variable If POSSIBLE ??</p>
  
  <p>Thanks</p>