title: namespaces in coffeescript
body: <p>I'd like to use namespaces as one would in javascript by using the keyword "with", but CoffeeScript reports this as a reserved keyword and refuses to compile is there any way I could use namespaces in cs?</p>
  
  <p>In particular, I want to include a CoffeeScript file dynamically (trusted source), like loading models for a database schema, but I want the included script to have access to a local namespace.</p>
  
  <hr>
  
  <p><strong>Edit:</strong></p>
  
  <p>Here's what I want to do. I am setting up a web framework that maps the directory tree to an application based on express and mongoose. For example, there's a sub-directory 'models' that contains a file 'user.coffee' with code like this inside:</p>
  
  <pre><code>name:
      type: String
      unique: on
  profiles: [ Profile ]
  </code></pre>
  
  <p>Whereby <code>Profile</code> is a class that sits in a local object named <code>model</code>. When the user model is being loaded, I wanted it to access the model classes that sit in my local model store. </p>
  
  <p>My work-around for now was to write <code>model.Profile</code> into the file 'user.coffee'. Hope it is clear what I mean.</p>
  
  <hr>
  
  <p><strong>2nd Edit</strong></p>
  
  <p>Here's how I did it without using <code>with</code>:</p>
  
  <p>user.coffee</p>
  
  <pre><code>name:
      type: String
      unique: on
  profiles: [ @profile ]
  </code></pre>
  
  <p>profile.coffee</p>
  
  <pre><code>content: String
  </code></pre>
  
  <p>And here's how it's dynamically loaded:</p>
  
  <pre><code>for fm in fs.readdirSync "#{base}/models"
      m = path.basename fm, '.coffee'
      schema[m] = (()-&gt;
          new Schema coffee.eval (
              fs.readFileSync "#{base}/models/#{fm}", 'utf8'
          ), bare: on
      ).call model
      mongoose.model m, schema[m]
      model[m] = mongoose.model m
  </code></pre>
  
  <p>Seems an okay solution to me.</p>