title: JavaScript: Using property in method that not defined in constructor?
body: <p>I saw this snippet of code below in <a href="https://medium.com/swlh/lets-code-a-client-side-router-for-your-no-framework-spa-19da93105e10" rel="nofollow noreferrer">article</a> </p>
  
  <p>where the developer using property (<code>this.props</code>) in method ( <code>setProps</code>) that is not defined in the constructor.</p>
  
  <pre><code>class Route{
    constructor(name,path,view){
      this.name = name;
      this.path = path;
      this.view = view;
    }
  
    setProps(newProps){
      this.props = props;
    }
  
    renderVeiw(){
      return this.veiw(this.props);
    }
  }
  
  const newElement = new Route('foo','bar','baz')
  
  console.log('fooo',newElement) 
  console.log('fooo',newElement.setProps('hello'))   
  </code></pre>
  
  <p>it's the first time for me to see this use case </p>
  
  <ul>
  <li>can anyone give me some explain? </li>
  <li>how to use it later because I tried to call the method with a random value but as I expected it will throw error </li>
  </ul>
  
  <p>my question is about this pattern not the snippet itself so feel free to give me any other simple example if possible </p>
  
  <hr>
  
  <p>Thanks </p>