basicclass.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. /**
  7. * A class implementing basic features useful for other classes.
  8. *
  9. * @class BasicClass
  10. * @mixins Emitter
  11. */
  12. CKEDITOR.define( [ 'emitter', 'utils' ], function( EmitterMixin, utils ) {
  13. function BasicClass() {
  14. }
  15. // Injects the events API.
  16. utils.extend( BasicClass.prototype, EmitterMixin );
  17. /**
  18. * Creates a subclass constructor based on this class.
  19. *
  20. * @abstract
  21. * @static
  22. * @inheritable
  23. *
  24. * @param {Object} [proto] Extensions to be added to the subclass prototype.
  25. * @param {Object} [statics] Extension to be added as static members of the subclass constructor.
  26. * @returns {Object} The subclass constructor.
  27. */
  28. BasicClass.extend = function( proto, statics ) {
  29. var that = this;
  30. var child = ( proto && proto.hasOwnProperty( 'constructor' ) ) ?
  31. proto.constructor :
  32. function() {
  33. that.apply( this, arguments );
  34. };
  35. // Copy the statics.
  36. utils.extend( child, this, statics );
  37. // Use the same prototype.
  38. child.prototype = Object.create( this.prototype );
  39. // Add the new prototype stuff.
  40. if ( proto ) {
  41. proto = utils.clone( proto );
  42. delete proto.constructor;
  43. utils.extend( child.prototype, proto );
  44. }
  45. return child;
  46. };
  47. return BasicClass;
  48. } );