FACG2 / getGitHub

1 stars 0 forks source link

Use Self-Invoking Function #36

Open mrm7moud opened 7 years ago

mrm7moud commented 7 years ago

Use Self-Invoking Function directly in dom function example:

(function dom() {
  if (typeof document != 'undefined') {
    var searchForm = document.getElementById('searchForm');
    if (searchForm) {
      searchForm.addEventListener('submit', function(event){
        event.preventDefault();
        var userName = event.target.firstElementChild.value;
        apiReq(userName , function(data){
          document.querySelector('.avatar img').setAttribute("src", data.avatar_url);
          document.querySelector('.names h1').textContent = data.name;
          document.querySelector('.names h6').textContent = data.login;
          document.querySelector('#company').textContent = data.company;
          document.querySelector('#location').textContent = data.location;
          document.querySelector('#followersNumber span').textContent = data.followers;
          document.querySelector('#followingNumber span').textContent = data.following;
          document.querySelector('.listRepos').innerHTML = myRepos(data.repos);
        });
      });
    }
  }
})();

https://github.com/FACG2/getGitHub/blob/2b645470496b5717e3ee73381e64079f0e1adc68/public/js/index.js#L1

Walidmash commented 7 years ago

its the samethink mahmoud, we are using the self-invoking function. but we call the dom inside it because we were thinking of invoking other functions in the same self-invoking function. Thank you mahmoud ^^