From 2d0b1a7e5c346ce404e24f149caa23a9c53e2dab Mon Sep 17 00:00:00 2001 From: Harold Putman Date: Thu, 10 Oct 2013 16:02:38 -0400 Subject: [PATCH] Preserve original constructor name This improves the debugging output since you can the class name instead of just Model/View/Collection by adding a named constructor like this: ```js constructor: function MyModel() { Backbone.Model.apply(this, arguments); }, ``` The debug output looks more like: ``` [instance] Model: MyModel:c6 ``` This also improves compatiblity with the Backbone-Debugger (https://github.com/Maluen/Backbone-Debugger/) chrome extension. --- backbone.debug.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backbone.debug.js b/backbone.debug.js index 573a266..9a6ef21 100644 --- a/backbone.debug.js +++ b/backbone.debug.js @@ -224,7 +224,8 @@ } else { originalConstructor = this; } - args[0].constructor = eval("(function " + object + "() { var ret = originalConstructor.apply(this, arguments); action(object, 'extend', this, arguments); return ret; })"); + var fname = originalConstructor.name ? originalConstructor.name : object; + args[0].constructor = eval("(function " + fname + "() { var ret = originalConstructor.apply(this, arguments); action(object, 'extend', this, arguments); return ret; })"); return originalExtend.apply(this, args); }; };