MyJsUtilities Testing

Random testing for Javascript utility library. https://github.com/zaus/MyJsUtilities

by drzaus

HTML

Open the DevTools console: <kbd>F12</kbd>.

<p>Look for output...shouldn't see stuff that tells you that you shouldn't see :)</p>

JavaScript

_log = (function (methods, undefined) {

    	var Log = Error; // does this do anything?  proper inheritance...?
    	Log.prototype.write = function (args, method) {
    		/// <summary>
    		/// Paulirish-like console.log wrapper.  Includes stack trace via @fredrik SO suggestion (see remarks for sources).
    		/// </summary>
    		/// <param name="args" type="Array">list of details to log, as provided by `arguments`</param>
    		/// <param name="method" type="string">the console method to use:  debug, log, warn, info, error</param>
    		/// <remarks>Includes line numbers by calling Error object -- see
    		/// * http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
    		/// * http://stackoverflow.com/questions/13815640/a-proper-wrapper-for-console-log-with-correct-line-number
    		/// * http://stackoverflow.com/a/3806596/1037948
    		/// </remarks>

    		// via @fredrik SO trace suggestion; wrapping in special construct so it stands out
    		var suffix = {
    			"@": (this.lineNumber
    					? this.fileName + ':' + this.lineNumber + ":1" // add arbitrary column value for chrome linking
    					: extractLineNumberFromStack(this.stack)
    			)
    		};
    
    		args = args.concat([suffix]);
    		// via @paulirish console wrapper
    		if (console && console[method]) {
    			if (console[method].apply) { console[method].apply(console, args); } else { console[method](args); } // nicer display in some browsers
    		}
    	};
    	var extractLineNumberFromStack = function (stack) {
    		/// <summary>
    		/// Get the line/filename detail from a Webkit stack trace.  See http://stackoverflow.com/a/3806596/1037948
    		/// </summary>
    		/// <param name="stack" type="String">the stack string</param>
    
    		// correct line number according to how Log().write implemented
    		var line = stack.split('\n')[3];
    		// fix for various display text
    		line = (line.indexOf(' (') >= 0
    			? line.split(' (')[1].substring(0,...