title: Is $(document.body) and document.body the same? Cleaning garbage and binding in class? - MooTools 1.3
body: <p>I am building a MooTools class and I have this in my initialize function:</p>
  
  <pre><code>this.css = null;
  
  window.addEvent('domready', function(){
  
      this.document = $(document);
      this.body = $(document.body);
      this.head = $(document.head);
  
  }.bind(this));
  </code></pre>
  
  <p>Ok and now to the questions ...
  Should I declare this.css = null or any other empty variable in the init:</p>
  
  <pre><code>this.css = null; // Maybe this.css = '' - empty string?
  </code></pre>
  
  <p>Next thing is about window and document ... Should I put it into $() or not because it works both way, so I just want to know which way is preferred? So to summarize:</p>
  
  <pre><code>window.addEvent() // or should I use $(window).addEvent()
  this.document = $(document) // or this.document = document
  this.body = $(document.body) // or this.body = document.body
  </code></pre>
  
  <p>I stored these values into object to avoid multiple DOM queries, is this ok? Or would it be better to call $(selector) / $$(selector) every time?</p>
  
  <p>Two more things left ... About binding ... Is it ok to use .bind(this) every time or would it be better to use .bind(this.myDiv) and use it inside function as eg.: this.setStyle(...); instead of this.myDiv.setStyle(...)</p>
  
  <pre><code>(function(){
    this.setStyle('overflow-y', 'visible');
   }.bind(this.body)).delay(100);
  </code></pre>
  
  <p>or</p>
  
  <pre><code>(function(){
    this.body.setStyle('overflow-y', 'visible');
   }.bind(this)).delay(100);
  </code></pre>
  
  <p>And the last thing is about garbage collection ... Do I have to garbage myself and how to do it (as far as I know MooTools does it on its own on unload). The confusing part is that I found function in MT docs:</p>
  
  <pre><code>myElement.destroy();
  </code></pre>
  
  <p>They say: Empties an Element of all its children, removes and garbages the Element. Useful to clear memory before the pageUnload.</p>
  
  <p>So I have to garbage on my own? How to do that? When to use .destroy()? I am working on a huge project and I notice that IE gets slow over multiple executions of the script (so how to handle that? probably some cleaning needed, memory leaks?).</p>