title: JavaScript dynamically add method to Object
body: <p>From JavaScript I want to connect and execute commands to MongoDB.<br>
  This works fine: <code>db.collection.find( new BasicDBObject("{name:'Vlad'}"))</code></p>
  
  <p>How do I dynamically add methods to the collection, so I can call <code>collection.find(string)</code>?<br>
  My goal is to be able to do something like the following without recompiling the MongoDB Java driver: <code>db.collection.find( {name:'Vlad'} ))</code></p>
  
  <p>In Groovy there is a library which does something similar: 
  <a href="https://github.com/poiati/gmongo" rel="nofollow">GMongo</a>; it has a nice tutorial on this page.<br>
  I would like to build the same for JavaScript Nashorn, and delegate all calls of <code>Cursor.find( Object )</code> to <code>Cursor.find( new BasicDbOBject( object ))</code>.<br>
  Is that possible in JavaScript?<br>
  I cannot extend the Cursor directly, this has to be done at run time, since the cursor is generated in the MongoDB Java driver.</p>