Wikia


//
////////////////////////////////////////////////////////////////////////////////////////////////////
// Module: Utilities
// This module contains several general purpose functions. These functions are too small, too
// few, and too diverse to form independent modules.
//
// Dependencies
// These files shall be included before this file is included:
// - none
////////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------------
We are using this function instead of window.console.assert because this function provides more
feedback.                                                                                         */
function assert(identifier, expected, actual) {
  if (actual === expected) return;
  console.error('assertion ' + identifier + ' failed: expected: \"' + expected + '\", got: \"' +
    actual + '\".');
}
/*--------------------------------------------------------------------------------------------------
This function returns the type of the specified object as string.
Calling this function with an undeclared parameter will result in a ReferenceError:
  getType(foo); //ReferenceError
Use typeof to check declaration:
  if (typeof foo !== 'undefined') ...                                                             */
function getType(obj) {
  if (obj == null) return 'null';
  return Object.prototype.toString.call(obj).slice(8, -1);
}
/*Examples:*/ {
  var b;
  var c = new String();
  assert('getType01', 'null', getType(b));
  assert('getType02', 'String', getType(c));
  assert('getType03', 'String', getType('literal'));
}
includer.moduleIncluded(1);
//

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Around Wikia's network

Random Wiki