Sfoglia il codice sorgente

Utils.mix() should not override existing properties.

Piotrek Koszuliński 10 anni fa
parent
commit
b9dfd25d9f
1 ha cambiato i file con 7 aggiunte e 1 eliminazioni
  1. 7 1
      packages/ckeditor5-ui/src/utils.js

+ 7 - 1
packages/ckeditor5-ui/src/utils.js

@@ -125,7 +125,9 @@ const utils = {
 	 *
 	 *		utils.mix( Editor, SomeMixin, ... );
 	 *
-	 *		new Editor().a(); -> 'a'
+	 *		new Editor().a(); // -> 'a'
+	 *
+	 * Note: Properties which already exist in the base class will not be overriden.
 	 *
 	 * @param {Function} [baseClass] Class which prototype will be extended.
 	 * @param {Object} [...mixins] Objects from which to get properties.
@@ -134,6 +136,10 @@ const utils = {
 		mixins.forEach( ( mixin ) => {
 			Object.getOwnPropertyNames( mixin ).concat( Object.getOwnPropertySymbols( mixin ) )
 				.forEach( ( key ) => {
+					if ( key in baseClass.prototype ) {
+						return;
+					}
+
 					const sourceDescriptor = Object.getOwnPropertyDescriptor( mixin, key );
 					sourceDescriptor.enumerable = false;