Browse Source

fix mixins going to wrong class

Adam Shaw 8 years ago
parent
commit
651cac9e16
2 changed files with 11 additions and 20 deletions
  1. 2 2
      src.json
  2. 9 18
      src/common/Class.js

+ 2 - 2
src.json

@@ -6,12 +6,12 @@
     "moment-ext.js",
     "date-formatting.js",
     "common/Class.js",
+    "common/EmitterMixin.js",
+    "common/ListenerMixin.js",
     "common/Model.js",
     "common/Promise.js",
     "common/TaskQueue.js",
     "common/RenderQueue.js",
-    "common/EmitterMixin.js",
-    "common/ListenerMixin.js",
     "common/Popover.js",
     "common/CoordCache.js",
     "common/DragListener.js",

+ 9 - 18
src/common/Class.js

@@ -8,25 +8,21 @@ function Class() { }
 // 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
+	var members = Object.assign.apply( // collapse all object args into one object
+		Object,
+		[ {} ].concat( // prepend empty object, as the destination
+			Array.prototype.slice.call(arguments) // needs to be a true array for concat
+		)
+	);
+
+	return extendClass(this, members);
 };
 
 
 // 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);
+	copyOwnProps(members, this.prototype);
 };
 
 
@@ -54,8 +50,3 @@ function extendClass(superClass, members) {
 
 	return subClass;
 }
-
-
-function mixIntoClass(theClass, members) {
-	copyOwnProps(members, theClass.prototype);
-}