Accessing javascript object property within nested function
<p>Good day,</p>

<p>I have created an object that will manage data access. My app will be using a couple different datastores, so I have created a simple factory to switch between providers:</p>

<pre><code>var dataProvider = {
company: {
    getAllCompanies: function (callback) {
        var impl = factory.createProvider(implInstance.current)
        impl.company.getAllCompanies(callback);
    }
}
projects: {
    getAllProjects: function (callback) {
        var impl = factory.createProvider(implInstance.current)
        impl.projects.getAllProjects(callback);
    }
}
}
</code></pre>

<p>That is all well and good, but I'd rather have my impl variable at the dataProvider level. I'm unsure how I would properly access it though, as 'this' doesn't provide me the right scope when I'm nested so deeply. I'd like something like the following:</p>

<pre><code>var dataProvider = {
impl: function () { return factory.createProvider(implInstance.current) },
company: {
    getAllCompanies: function (callback) {
        //THIS WON'T WORK
        this.impl.company.getAllCompanies(callback);
    }
}
</code></pre>

<p>Thanks!</p>
