JQuery Self in Data
<p>I am having trouble with the following code:</p>

<pre><code>function Class() {
    var self = this;
    var $div = $('&lt;div/&gt;');
    $div.data('obj',self);

    this.get = function() {
        return $div;
    }
}

var x = new Class();
var $y = x.get();
</code></pre>

<p><a href="http://jsfiddle.net/t8ZTW/2/" rel="nofollow">http://jsfiddle.net/t8ZTW/2/</a></p>

<p>The problem is that I store the object "self" data using jQuery's .data() function, but I cannot seem to access it later.  What is going wrong?</p>

<p>EDIT:</p>

<p>The following is the code I should actually be asking about:</p>

<pre><code>function Class() {
    var self = this;
    var $div = $('&lt;div/&gt;');
    $div.data('obj',self);

    var sample = "S";

    this.get = function() {
        return $div;
    }
}

var x = new Class();
var $y = x.get();

alert($y.data('obj').sample); // &lt;-- This returns 'undefined'
</code></pre>
