utils.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 utilities library.
  8. *
  9. * @class utils
  10. * @singleton
  11. */
  12. CKEDITOR.define( function() {
  13. return {
  14. /**
  15. * Extends one JavaScript object with the properties defined in one or more objects. Existing properties are
  16. * overridden.
  17. *
  18. * @param {Object} target The object to be extended.
  19. * @param {Object} source One or more objects which properties will be copied (by reference) to `target`.
  20. * @returns {Object} The `target` object.
  21. */
  22. extend: function( target, source ) {
  23. if ( !this.isObject( source ) ) {
  24. return target;
  25. }
  26. var args, keys, i;
  27. if ( arguments.length > 2 ) {
  28. args = Array.prototype.splice.call( arguments, 1 );
  29. i = args.length;
  30. while ( i-- ) {
  31. this.extend( target, args[ i ] );
  32. }
  33. } else {
  34. keys = Object.keys( source );
  35. i = keys.length;
  36. while ( i-- ) {
  37. target[ keys[ i ] ] = source[ keys[ i ] ];
  38. }
  39. }
  40. return target;
  41. },
  42. /**
  43. * Checks if the provided object is a JavaScript function.
  44. *
  45. * @param obj The object to be checked.
  46. * @returns {Boolean} `true` if the provided object is a JavaScript function. Otherwise `false`.
  47. */
  48. isFunction: function( obj ) {
  49. return typeof obj == 'function';
  50. },
  51. /**
  52. * Checks if the provided object is a "pure" JavaScript object. In other words, if it is not any other
  53. * JavaScript native type, like Number or String.
  54. *
  55. * @param obj The object to be checked.
  56. * @returns {Boolean} `true` if the provided object is a "pure" JavaScript object. Otherwise `false`.
  57. */
  58. isObject: function( obj ) {
  59. return typeof obj === 'object' && !!obj;
  60. }
  61. };
  62. } );