backbone icon indicating copy to clipboard operation
backbone copied to clipboard

0.9.10 model.set('img', new Image()) crashes

Open adrianortuzar opened this issue 13 years ago • 2 comments

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 ...

adrianortuzar avatar Jan 26 '13 17:01 adrianortuzar

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.

lukeasrodgers avatar Jan 26 '13 18:01 lukeasrodgers

It works, thanks¡¡

adrianortuzar avatar Jan 26 '13 18:01 adrianortuzar