Source: node_modules/bson/lib/bson/code.js

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