documentcloud/backbone — Issue #795: Stack overflow while saving Backbone.js model
Author: duncan-bayne
Created: 2011-12-17 23:33:46+00:00
State: open

I have a simple Backbone.js model:

class Avia.Student extends Backbone.Model

Told you it was simple :-) Anyhow, I'm saving it in the following view (snipped for clarity):

class Avia.StudentView extends Backbone.View

render: =>
html = JST['views/student_view_template'](model: @model)
@el.html(html)
Backbone.ModelBinding.bind(@)
$('#save').bind('click', @save)

save: (e) =>
e.preventDefault()
@model.save(
success: =>,
error: =>
)

When I click the save button, @save() is called, but fails with the following error (again, snipped for clarity as obviously it continues for a long time):

Uncaught RangeError: Maximum call stack size exceeded
Backbone.Events.trigger:117
_.extend._onModelEvent:635
Backbone.Events.trigger:117
_.extend._onModelEvent:635
Backbone.Events.trigger:117
_.extend._onModelEvent:635
Backbone.Events.trigger:117

I've tried commented out Backbone.ModelBinding.bind(@), and I've ensured #save is unique by renaming it to #wooble and renaming the associated bindings.

I've also tried using the very latest backbone.js from GitHub.

Still the problem persists :-/

(I've also asked this as [a question over on StackOverflow](http://stackoverflow.com/questions/8542651/stack-overflow-while-saving-backbone-js-model) because I initially suspected PEBKAC on my part. I'm still not so sure it isn't.)