javascript variable scope in callbacks
<p>I'm curious how could this be written better:</p>

<pre><code>function Klass(variable) {
    this.variable = variable;

    this.callAjax = function() {
        $.get('/url', { }, function(json) {
            console.log(variable); //! &lt;-- shows undefined
        }, "json");
    }
}
</code></pre>

<p>so I create a local variable: _variable</p>

<pre><code>function Klass(variable) {
    this.variable = variable;

    this.callAjax = function() {
        var _variable = this.variable;
        $.get('/url', { }, function(json) {
            console.log(_variable); //! &lt;-- its ok
        }, "json");
    }
}
</code></pre>

<p>and its fine, but I really don't this solutions,</p>

<p>Does someone of you have a better code?</p>
