Browse Source

ES6-y the simple mix() method.

Piotrek Koszuliński 10 years ago
parent
commit
45ea7c5400
1 changed files with 8 additions and 9 deletions
  1. 8 9
      packages/ckeditor5-ui/src/utils.js

+ 8 - 9
packages/ckeditor5-ui/src/utils.js

@@ -110,8 +110,8 @@ const utils = {
 	},
 
 	/**
-	 * Copies enumerable properties from the objects given as 2nd+ parameters to the
-	 * prototype of the base class.
+	 * Copies enumerable properties and symbols from the objects given as 2nd+ parameters to the
+	 * prototype of first object (a constructor).
 	 *
 	 *		class SpecificEditor extends utils.mix( Editor, SomeMixin1, SomeMixin2 ) {
 	 *			...
@@ -122,14 +122,13 @@ const utils = {
 	 */
 	mix( baseClass, ...mixins ) {
 		mixins.forEach( ( mixin ) => {
-			Object.keys( mixin ).forEach( ( key ) => {
-				Object.defineProperty( baseClass.prototype, key, {
-					enumerable: false,
-					configurable: true,
-					writable: true,
-					value: mixin[ key ]
+			Object.getOwnPropertyNames( mixin ).concat( Object.getOwnPropertySymbols( mixin ) )
+				.forEach( ( key ) => {
+					const sourceDescriptor = Object.getOwnPropertyDescriptor( mixin, key );
+					sourceDescriptor.enumerable = false;
+
+					Object.defineProperty( baseClass.prototype, key, sourceDescriptor );
 				} );
-			} );
 		} );
 	}
 };