title: AngularJS scope of THIS in Factory
body: <p>I'm very confusing because of 'this' property.</p>
  
  <p>What does "<code>delete this.user;</code>" mean in <code>AuthenticationFactory</code>. I think function "<code>check</code>" is a method so it will be bind with '<code>auth</code>' object. But, there is no '<code>user</code>' property in '<code>auth</code>' Object. Can you explain it?</p>
  
  <p>Also, in '<code>UserAuthFactory</code>' (<code>delete AuthenticationFactory.user</code>, <code>delete AuthenticationFactory.userRole</code>)</p>
  
  <p>I can't figure out what are "<code>user</code>" and "<code>userRole</code>" properties. There are no such properties in <code>AuthenticationFactory</code>.</p>
  
  <p>Here the my code from <a href="http://thejackalofjavascript.com/architecting-a-restful-node-js-app/" rel="nofollow">http://thejackalofjavascript.com/architecting-a-restful-node-js-app/</a></p>
  
  <pre><code>myApp.factory('AuthenticationFactory', function($window) {
    var auth = {
      isLogged: false,
      check: function() {
        if ($window.sessionStorage.token &amp;&amp; $window.sessionStorage.user) {
          this.isLogged = true;
        } else {
          this.isLogged = false;
          delete this.user;
        }
      }
    }
  
    return auth;
  });
  
  myApp.factory('UserAuthFactory', function($window, $location, $http, AuthenticationFactory) {
    return {
      login: function(username, password) {
        return $http.post('http://localhost:3000/login', {
          username: username,
          password: password
        });
      },
      logout: function() {
  
        if (AuthenticationFactory.isLogged) {
  
          AuthenticationFactory.isLogged = false;
          delete AuthenticationFactory.user;
          delete AuthenticationFactory.userRole;
  
          delete $window.sessionStorage.token;
          delete $window.sessionStorage.user;
          delete $window.sessionStorage.userRole;
  
          $location.path("/login");
        }
  
      }
    }
  });
  </code></pre>