Returning an object from a Class like mongoose

How is mongoose.js returning an object from:

var silence = new Kitten({
  name: 'Silence'
});

console.log(silence); // { name: 'Silence' }

But if you check the source code Kitten is a function called model on this code which then points to the document source code here.

function Document (obj, fields, skipId) {
  this.$__ = new InternalCache;
  this.isNew = true;
  this.errors = undefined;
  //...
  this._doc = this.$__buildDoc(obj, fields, skipId);
  if (obj) {
    this.set(obj, undefined, true);
  }
}

Which means it should be returning something like:

var silence = new Kitten({
  name: 'Silence'
});

console.log(silence); // { _obj: { name: 'Silence' } }

So how is it that they are returnin another object than the constructed class itself?


Further investigation:

Manually changing the ret here makes the class return that specified ret.