classic.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. };