Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>ctx</code> is used as the value of <code>this</code> inside the callback function when an event is triggered. So for example, inside the <code>initialize</code> method of a view you might do this:</p> <pre><code>this.model.on('change', this.render, this); // where 'this' is the view </code></pre> <p>Then inside the render method, when that event is triggered, <code>this</code> will be the view.</p> <p><code>context</code> is used so that certain usages of <code>off</code> can work, giving you more ways to selectively remove event callbacks. For example, if you wanted to remove the callbacks added to the model in the above example, you could do this:</p> <pre><code>this.model.off(null, null, this); // where 'this' is the view from above </code></pre> <p>This would remove any event handlers added to that model where the view was passed as the context. </p> <p>That line would not remove an event added like:</p> <pre><code>this.model.on('change', this.foo, bar); // context is bar </code></pre> <p>It could be useful if you hooked up to several events and wanted to remove them all at once, while not removing any callbacks added with different context. However, now that Events has <code>listenTo</code>, it is probably easier to use that instead, since the view could just call <code>stopListening</code>.</p> <p>The reason <code>context</code> and <code>ctx</code> are stored separately, is because they can be different values. <code>context</code> is always the third value passed to <code>on</code> and it could be null or undefined, while <code>ctx</code> is either that value, if available, or <code>this</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload