title: What's the best way to write a portable Javascript library?
body: <p>All of my projects include very similar tasks and quite recently I've been thinking I should write a library to handle most of the heavy lifting so I can write short, simple, easy to read code that interacts with the library to get the jobs done.  Looking at other frameworks, specifically jQuery &amp; YUI, they work in different ways.  jQuery mostly seems to extend &amp; simplify the DOM using a global object/function whereas YUI uses namespaces and modules.  I understand that this is because they have different goals as libraries and each have their merits.</p>
  
  <p>Most specifically, I'm looking for answers to the following questions:</p>
  
  <ol>
  <li>Is it best to use namespaces, eg <code>gui.scrollbar.attach()</code>, or a global method such as <code>$(domObj).attachScrollbar()</code>?</li>
  <li>Is it best to include individual parts as seperate js files or as a single js file where components are copied/pasted?  I know the eBay Shopping API SDK has many .js files in seperate folders, wouldn't this suffer a significant performance hit?</li>
  <li>Is there any other advice you would give to someone looking to create a javascript library?</li>
  </ol>
  
  <p>I've marked as community wiki because I didn't want to risk the question being closed - I'm genuinely seeking advice here.</p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT</strong>
  I should have originally stated that I'm not re-inventing the wheel, I'm looking to simplify many common tasks between Windows Desktop Gadgets, so I don't need the cross-browser compatibility of other libraries and their core functionality doesn't really apply to what I'm doing.  I tried to keep the question general and not specifically relating to desktop gadgets, so that this question would be useful for others.</p>