code.js 556 B

123456789101112131415161718192021222324
  1. /**
  2. * A class representation of the BSON Code type.
  3. *
  4. * @class
  5. * @param {(string|function)} code a string or function.
  6. * @param {Object} [scope] an optional scope for the function.
  7. * @return {Code}
  8. */
  9. var Code = function Code(code, scope) {
  10. if(!(this instanceof Code)) return new Code(code, scope);
  11. this._bsontype = 'Code';
  12. this.code = code;
  13. this.scope = scope == null ? {} : scope;
  14. };
  15. /**
  16. * @ignore
  17. */
  18. Code.prototype.toJSON = function() {
  19. return {scope:this.scope, code:this.code};
  20. }
  21. module.exports = Code;
  22. module.exports.Code = Code;