javascript - get function name or some unique id of function from object -
window.vo = {}; window.viewobjects = function (viewname, view) { if (viewname in vo) { console.log('unbinding'); vo[viewname].undelegateevents(); } vo[viewname] = view; return view; };
i wrote above function deal multiple rendering of same view.
but need pass unique name each view.
window.viewobjects('booksindex', new views.dashboard.books.index());
is there way can avoid argument viewname?
any way name of function view object.
but issue when have views like
dashboard.books.index() dashboard.stores.index()
all backbone views have cid
(client id) unique. use id identify views instead of assigning different name.
something this:
window.vo = {}; window.viewobjects = function (view) { if (view.cid in vo) { console.log('unbinding'); vo[view.cid].undelegateevents(); } vo[view.cid] = view; return view; };
the relevant part extracted backbone annotated code new unique cid
set on view creation:
var view = backbone.view = function(options) { this.cid = _.uniqueid('view'); options || (options = {}); _.extend(this, _.pick(options, viewoptions)); this._ensureelement(); this.initialize.apply(this, arguments); };
Comments
Post a Comment