backbone
backbone copied to clipboard
0.9.10 model.set('img', new Image()) crashes
Hi, Im working with Backbone.js 0.9.10, and when I try to set a new Image() in a model like this:
var Image = Backbone.Model.extend( { idAttribute: "_id", defaults:{ 'img': null }, initialize: function(){ this.set('img', new Image()); } });
browser crashes and the console give me this error:
b.defaults g.Model r.extend.s.extend.y.extend.A.extend.m.extend.d Backbone.Model.extend.initialize g.Model ...
Looks like the problem is you're overwriting native Image constructor, then when in initialize you call new Image() you get into infinite recursion.
Try the same code with var ImageModel instead of var Image.
It works, thanks¡¡