classic.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Generated by CoffeeScript 1.6.3
  2. var classic,
  3. __slice = [].slice;
  4. module.exports = classic = {};
  5. classic.implement = function() {
  6. var classProto, classReference, desc, member, mixin, mixins, _i, _j, _len;
  7. mixins = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), classReference = arguments[_i++];
  8. for (_j = 0, _len = mixins.length; _j < _len; _j++) {
  9. mixin = mixins[_j];
  10. classProto = classReference.prototype;
  11. for (member in mixin.prototype) {
  12. if (!Object.getOwnPropertyDescriptor(classProto, member)) {
  13. desc = Object.getOwnPropertyDescriptor(mixin.prototype, member);
  14. Object.defineProperty(classProto, member, desc);
  15. }
  16. }
  17. }
  18. return classReference;
  19. };
  20. classic.mix = function() {
  21. var classProto, classReference, desc, member, mixin, mixins, _i, _j, _len;
  22. mixins = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), classReference = arguments[_i++];
  23. classProto = classReference.prototype;
  24. classReference.__mixinCloners = [];
  25. classReference.__applyClonersFor = function(instance, args) {
  26. var cloner, _j, _len, _ref;
  27. if (args == null) {
  28. args = null;
  29. }
  30. _ref = classReference.__mixinCloners;
  31. for (_j = 0, _len = _ref.length; _j < _len; _j++) {
  32. cloner = _ref[_j];
  33. cloner.apply(instance, args);
  34. }
  35. };
  36. classReference.__mixinInitializers = [];
  37. classReference.__initMixinsFor = function(instance, args) {
  38. var initializer, _j, _len, _ref;
  39. if (args == null) {
  40. args = null;
  41. }
  42. _ref = classReference.__mixinInitializers;
  43. for (_j = 0, _len = _ref.length; _j < _len; _j++) {
  44. initializer = _ref[_j];
  45. initializer.apply(instance, args);
  46. }
  47. };
  48. classReference.__mixinQuitters = [];
  49. classReference.__applyQuittersFor = function(instance, args) {
  50. var quitter, _j, _len, _ref;
  51. if (args == null) {
  52. args = null;
  53. }
  54. _ref = classReference.__mixinQuitters;
  55. for (_j = 0, _len = _ref.length; _j < _len; _j++) {
  56. quitter = _ref[_j];
  57. quitter.apply(instance, args);
  58. }
  59. };
  60. for (_j = 0, _len = mixins.length; _j < _len; _j++) {
  61. mixin = mixins[_j];
  62. if (!(mixin.constructor instanceof Function)) {
  63. throw Error("Mixin should be a function");
  64. }
  65. for (member in mixin.prototype) {
  66. if (member.substr(0, 11) === '__initMixin') {
  67. classReference.__mixinInitializers.push(mixin.prototype[member]);
  68. continue;
  69. } else if (member.substr(0, 11) === '__clonerFor') {
  70. classReference.__mixinCloners.push(mixin.prototype[member]);
  71. continue;
  72. } else if (member.substr(0, 12) === '__quitterFor') {
  73. classReference.__mixinQuitters.push(mixin.prototype[member]);
  74. continue;
  75. }
  76. if (!Object.getOwnPropertyDescriptor(classProto, member)) {
  77. desc = Object.getOwnPropertyDescriptor(mixin.prototype, member);
  78. Object.defineProperty(classProto, member, desc);
  79. }
  80. }
  81. }
  82. return classReference;
  83. };