But identifying these views is not easy because models extended from Backbone Model/View have their constructor named child in the Heap Profiler.
A solution to this problem would be the possibility to name the constructors. Here is a simple hack to do that :
In backbone.js, around line 1541 :
123456789
// The constructor function for the new subclass is either defined by you// (the "constructor" property in your `extend` definition), or defaulted// by us to simply call the parent's constructor.if(protoProps&&_.has(protoProps,'constructor')){child=protoProps.constructor;}else{child=function(){returnparent.apply(this,arguments);};}
Simply add a case for an optional constructor name :
123456789
if(protoProps&&_.has(protoProps,'constructor')){child=protoProps.constructor;}elseif(_.has(protoProps,'constructorName')){eval("child = function "+protoProps.constructorName+"() { return parent.apply(this, arguments); };");}else{child=function(){returnparent.apply(this,arguments);};}
Note: due to the use of ‘eval’ it is not safe in production…
Now we can add a ‘constructorName’ in our models/views.