util.js 918 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. var util = {
  2. debug: false,
  3. inherits: function(ctor, superCtor) {
  4. ctor.super_ = superCtor;
  5. ctor.prototype = Object.create(superCtor.prototype, {
  6. constructor: {
  7. value: ctor,
  8. enumerable: false,
  9. writable: true,
  10. configurable: true
  11. }
  12. });
  13. },
  14. extend: function(dest, source) {
  15. for(var key in source) {
  16. if(source.hasOwnProperty(key)) {
  17. dest[key] = source[key];
  18. }
  19. }
  20. return dest;
  21. },
  22. randomId: function () {
  23. return Math.random().toString(36).substr(2);
  24. },
  25. prettyError: function (msg) {
  26. if (util.debug) {
  27. console.log('ERROR PeerServer: ', msg);
  28. }
  29. },
  30. log: function() {
  31. if (util.debug) {
  32. var copy = [];
  33. for (var i = 0; i < arguments.length; i += 1) {
  34. copy[i] = arguments[i];
  35. }
  36. console.log.apply(console, copy);
  37. }
  38. }
  39. };
  40. // if node
  41. module.exports = util;
  42. // end node