Passing a bound object method in JavaScript
<p>For a Firefox extension, I'm trying to do the following:</p>

<ol>
<li>Setup an object with two methods and a field/property/attribute</li>
<li>One of the methods has to be able to call the other method and access the attribute</li>
<li>I want to register that method as an event listener.</li>
</ol>

<p>Right now, I have it setup like a class:</p>

<pre><code>var Obj = {
  field: null,
  a: function() { }
  b: function() {
    Obj.field = 'x';
    Obj.a();
  }
}

window.addEventListener('mouseup', Obj.b, false);
</code></pre>

<p>But it seems like it should be possible to have the mod not refer to the object "from the outside" (e.g. by using <code>Obj</code>), but using just <code>this</code> instead. However, I can't figure out how to get this to work correctly, pass a simple function reference to <code>addEventListener()</code> <em>and</em> (preferably) only polluting the namespace with a single name. Is that possible? I tried googling for it and found e.g. <a href="http://ejohn.org/blog/simple-class-instantiation/" rel="nofollow">http://ejohn.org/blog/simple-class-instantiation/</a>, but that didn't seem to lead to something that fits my criteria of a clean setup.</p>
