Bug Tracker

Opened 10 years ago

Closed 9 years ago

#5275 closed enhancement (wontfix)

jquery.extend should set displayName on functions

Reported by: dwt Owned by:
Priority: minor Milestone: 1.4
Component: core Version: 1.3.2
Keywords: Cc: felix.schwarz@…
Blocked by: Blocking:

Description

Both Firebug and the Safari debugger support the convention that if a function has the displayName propperty set, that will be used to display it's name in the debugger.

(see : http://www.alertdebugging.com/2009/04/29/building-a-better-javascript-profiler-with-webkit/)

This is mightily usefull as one doesn't get as many 'anonymous functions) in the stacktrace which makes it much easier to work with it.

Here's a monkey-patched version that does enough to make it useful for me - but this should really be in the core of jQuery Extend:

(function() {
	var oldExtend = $.fn.extend;
	
	function isSecondArgumentDictionary(arguments) {
		var methodDict = arguments[1];
		return (2 === arguments.length)
			&& (null !== methodDict || 'object' === typeof(methodDict));
	}
	
	$.extend = function namingExtend() {
		if (isSecondArgumentDictionary(arguments)) {
			var methodDict = arguments[1];
			for (var key in arguments[1]) {
				if ($.isFunction(methodDict[key]) 
					&& ! methodDict[key].displayName)
					methodDict[key].displayName = key;
			}
		}
		return oldExtend.apply(this, arguments);
	};
	
}());

Change History (3)

comment:1 Changed 10 years ago by dmethvin

Priority: majorminor
Type: bugenhancement

comment:2 Changed 10 years ago by dwt

Does this have any chance of getting into core? I gather it is very usefull to all users while not having any incompatibility problems at all.

comment:3 Changed 9 years ago by snover

Resolution: wontfix
Status: newclosed

This should go into a debug plugin, not core.

Note: See TracTickets for help on using tickets.