mixin.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. (function() {
  2. var ExcludedClassProperties, ExcludedPrototypeProperties, Mixin, name;
  3. module.exports = Mixin = (function() {
  4. Mixin.includeInto = function(constructor) {
  5. var name, value, _ref;
  6. this.extend(constructor.prototype);
  7. for (name in this) {
  8. value = this[name];
  9. if (ExcludedClassProperties.indexOf(name) === -1) {
  10. if (!constructor.hasOwnProperty(name)) {
  11. constructor[name] = value;
  12. }
  13. }
  14. }
  15. return (_ref = this.included) != null ? _ref.call(constructor) : void 0;
  16. };
  17. Mixin.extend = function(object) {
  18. var name, _i, _len, _ref, _ref1;
  19. _ref = Object.getOwnPropertyNames(this.prototype);
  20. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  21. name = _ref[_i];
  22. if (ExcludedPrototypeProperties.indexOf(name) === -1) {
  23. if (!object.hasOwnProperty(name)) {
  24. object[name] = this.prototype[name];
  25. }
  26. }
  27. }
  28. return (_ref1 = this.prototype.extended) != null ? _ref1.call(object) : void 0;
  29. };
  30. function Mixin() {
  31. if (typeof this.extended === "function") {
  32. this.extended();
  33. }
  34. }
  35. return Mixin;
  36. })();
  37. ExcludedClassProperties = ['__super__'];
  38. for (name in Mixin) {
  39. ExcludedClassProperties.push(name);
  40. }
  41. ExcludedPrototypeProperties = ['constructor', 'extended'];
  42. }).call(this);