Adam Shaw 10 лет назад
Родитель
Сommit
87e699e5b5
3 измененных файлов с 37 добавлено и 16 удалено
  1. 33 12
      src/common/Class.js
  2. 2 2
      src/common/DayGrid.js
  3. 2 2
      src/common/TimeGrid.js

+ 33 - 12
src/common/Class.js

@@ -1,15 +1,37 @@
 
 FC.Class = Class; // export
 
-// class that all other classes will inherit from
+// Class that all other classes will inherit from
 function Class() { }
 
-// called upon a class to create a subclass
-Class.extend = function(members) {
-	var superClass = this;
-	var subClass;
 
-	members = members || {};
+// Called on a class to create a subclass.
+// Last argument contains instance methods. Any argument before the last are considered mixins.
+Class.extend = function() {
+	var len = arguments.length;
+	var i;
+	var members;
+
+	for (i = 0; i < len; i++) {
+		members = arguments[i];
+		if (i < len - 1) { // not the last argument?
+			mixIntoClass(this, members);
+		}
+	}
+
+	return extendClass(this, members || {}); // members will be undefined if no arguments
+};
+
+
+// Adds new member variables/methods to the class's prototype.
+// Can be called with another class, or a plain object hash containing new members.
+Class.mixin = function(members) {
+	mixIntoClass(this, members);
+};
+
+
+function extendClass(superClass, members) {
+	var subClass;
 
 	// ensure a constructor for the subclass, forwarding all arguments to the super-constructor if it doesn't exist
 	if (hasOwnProp(members, 'constructor')) {
@@ -32,10 +54,9 @@ Class.extend = function(members) {
 	copyOwnProps(superClass, subClass);
 
 	return subClass;
-};
+}
 
-// adds new member variables/methods to the class's prototype.
-// can be called with another class, or a plain object hash containing new members.
-Class.mixin = function(members) {
-	copyOwnProps(members.prototype || members, this.prototype); // TODO: copyNativeMethods?
-};
+
+function mixIntoClass(theClass, members) {
+	copyOwnProps(members.prototype || members, theClass.prototype); // TODO: copyNativeMethods?
+}

+ 2 - 2
src/common/DayGrid.js

@@ -2,7 +2,7 @@
 /* A component that renders a grid of whole-days that runs horizontally. There can be multiple rows, one per week.
 ----------------------------------------------------------------------------------------------------------------------*/
 
-var DayGrid = FC.DayGrid = Grid.extend($.extend({}, DayTableMixin, {
+var DayGrid = FC.DayGrid = Grid.extend(DayTableMixin, {
 
 	numbersVisible: false, // should render a row for day/week numbers? set by outside view. TODO: make internal
 	bottomCoordPadding: 0, // hack for extending the hit area for the last row of the coordinate grid
@@ -417,4 +417,4 @@ var DayGrid = FC.DayGrid = Grid.extend($.extend({}, DayTableMixin, {
 		return skeletonEl;
 	}
 
-}));
+});

+ 2 - 2
src/common/TimeGrid.js

@@ -3,7 +3,7 @@
 ----------------------------------------------------------------------------------------------------------------------*/
 // We mixin DayTable, even though there is only a single row of days
 
-var TimeGrid = FC.TimeGrid = Grid.extend($.extend({}, DayTableMixin, {
+var TimeGrid = FC.TimeGrid = Grid.extend(DayTableMixin, {
 
 	slotDuration: null, // duration of a "slot", a distinct time segment on given day, visualized by lines
 	snapDuration: null, // granularity of time for dragging and selecting
@@ -528,4 +528,4 @@ var TimeGrid = FC.TimeGrid = Grid.extend($.extend({}, DayTableMixin, {
 		return segs;
 	}
 
-}));
+});