1

http://jsfiddle.net/sbel/3KAhC/

In this fiddle code the even though the stopListening method is called the on method is still in effect as can be seen by the output. What am I doing wrong?

JavaScript:

// Define View
var SomeView = Backbone.View.extend({
    initialize: function () {
        // Listen to the model
        this.model.on('change', this.render, this);
    },

    render: function () {
        $("#message").append("<br>render called");
    },

    close: function () {
        this.stopListening();
    }
});

var SomeModel = Backbone.Model.extend({});

var someModel = new SomeModel({
    name: 'Foo'
});
var someView = new SomeView({
    model: someModel
});

someModel.set('name', 'Bar');
someView.close();
someView = null;
someModel.set('name', 'Zoo');
4

1 に答える 1