0.9.9骨干:ListenTo和区别 [英] Backbone 0.9.9: Difference between ListenTo and on

查看:128
本文介绍了0.9.9骨干:ListenTo和区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想学习骨干0.9.9他们做了新的变化。

I am trying to learn the new changes they did in Backbone 0.9.9.

目前我有问题要了解ListenTo之间的区别:

Currently I got problems to understand the difference between ListenTo and on:

listenTo

var View = Backbone.View.extend({

    tagName: "div",

    intialize: function() {
        this.listenTo(this.model, 'change', this.render);
    },

    render: function() {
        this.$el.empty();
        this.$el.append('<p>hello world</p>');
    }

});

var View = Backbone.View.extend({

    tagName: "div",

    intialize: function() {
        this.model.on('change', this.render, this);
    },

    render: function() {
        this.$el.empty();
        this.$el.append('<p>hello world</p>');
    }

});

我听说listenTo用的stopListening允许时,例如视图被删除,以避免内存泄漏,从所有活动取消。

I have heard that listenTo allows with stopListening to unsubscribe from all events when for example the view gets removed to avoid memory leaks.

这是唯一的原因?

问候,
博德

推荐答案

listenTo 的stopListening 从社区来了,基本上是这样。它们有助于更容易地结合并解除绑定事件。

listenTo and stopListening came from the community, basically. They help to make it easier to bind and unbind events.

有很多周围的念头现有的文件和博客文章,其中包括的东西,我已经写了关于这个问题的。

There's a lot of existing documentation and blog posts surrounding the idea, including stuff that I've written on the subject.

约翰尼大鹿是我看到使用这种技术的第一人。它最初被张贴的答案,这里StackOverflow的问题:<一href=\"http://stackoverflow.com/questions/7567404/backbone-js-repopulate-or-recreate-the-view/7607853#7607853\">Backbone.js :重新填充或重新创建视图

Johnny Oshika is the first person that I saw using this technique. It was originally posted as an answer to a StackOverflow question here: Backbone.js : repopulate or recreate the view?

您可以读到我写这个,在这里:

You can read what I've written about this, here:

  • Backbone.EventBinder: Better Event Management For Your Backbone Apps
  • Zombies! RUN! (Managing Page Transitions In Backbone Apps)
  • Backbone.js And JavaScript Garbage Collection

这篇关于0.9.9骨干:ListenTo和区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆