title: Get variable outside scope from a function inside an object - Javascript
body: <p>I have a function inside an object inside a Class.</p>
  
  <p>The object of the class is initialized and I want to call the function, but the function need a variable defined on the constructor of the Class.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>class someClass {
    constructor() {
      this.foo = "bar";
  
      this.print = {
        variable: function() {
          console.log(this.foo);
        }
      };
  
    }
  }
  
  // And I call it from the global scope
  
  var someObject = new someClass();
  
  someObject.print.variable();</code></pre>
  </div>
  </div>
  </p>
  
  <p>It will print</p>
  
  <blockquote>
    <p>undefined</p>
  </blockquote>
  
  <p>I know is a different scope and maybe I can't access to it.</p>
  
  <p>The objective of this is to have some order with my functions.</p>
  
  <p><strong>I want to access to my function like someObject.print.variable();</strong></p>