Presented here is a basic model:
myTestModel = Backbone.Model.extend({
defaults: {
title: 'My Title',
config: {},
active: 1,
}
})
While nothing particularly stands out, there is an interesting observation regarding the persistence of values in the config
option between instances. To illustrate this:
var test1 = new myTestModel();
test1.set('title', 'A New Title');
test1.get('config').screen_name = 'Joe';
alert( test1.get('title') ); // 'A New Title', as expected.
alert( test1.get('config').screen_name ); // 'Joe', as expected.
var test2 = new myTestModel();
alert( test2.get('title') ); // 'My Title', as expected.
alert( test2.get('config').screen_name ); // 'Joe', NOT as expected.
The concern that arises is why in test2
, the value of screen_name
from test1
is maintained. The question then becomes, how can this unintended behavior be prevented?