Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think what you are looking for is prototype style "bind"</p> <p>Basically "this.myCallback(this)" is a call to the function.</p> <p>this.myCallback is the function itself. (It is an object with the type function).</p> <p>You can call it using the method 'call' or 'apply' that you can use on functions. Which will call these functions.</p> <p>See:</p> <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call</a></p> <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply?redirectlocale=en-US&amp;redirectslug=JavaScript%2FReference%2FGlobal_Objects%2FFunction%2Fapply" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply?redirectlocale=en-US&amp;redirectslug=JavaScript%2FReference%2FGlobal_Objects%2FFunction%2Fapply</a></p> <p>The first argument is the object context to work in. What I think you mean by object namespace.</p> <p>so: <code>a.callback(5)</code> is the same as <code>a.callback.call(a,5)</code></p> <p>However please note that these days if you are working with most javascript libraries you probably have a 'bind' function that will do the work for you.</p> <p><a href="http://prototypejs.org/doc/latest/language/Function/prototype/bind/" rel="nofollow">http://prototypejs.org/doc/latest/language/Function/prototype/bind/</a></p> <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind</a></p> <p>the idea is that <code>this.callback.bind(this)</code> returns a Function object you can call that will inject the correct context automatically so you can pass the return value of bind alone as a callback and be assured that the method will be executed on the correct object.</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. This table or related slice is empty.
    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