Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Update:</strong> <code>kitty</code> is an <em>instance</em> of <code>Animal</code>. So it'll never say kitty. All those <code>proxy</code> wrappers are careful misdirections.</p> <p>Lets see:</p> <pre><code>(function($, exports){ var animal = function(){}; exports.Animal = animal; })(jQuery, window); </code></pre> <p>Just a disguise to say: <code>window.Animal = function(){};</code></p> <p>You're creating an anonymous function passing jQuery and window object to it and executing it immediately. This creates <code>Animal</code> class in <code>window</code> scope</p> <hr> <p>Now jquery.proxy allows you to change the context of a function: <code>jQuery.proxy( functionName, context )</code> - so inside <code>functionName</code>, <code>this</code> refers to <code>context</code> (<code>this == context</code>).</p> <p><code>$.proxy(kitty.sayHi, kitty)</code> says call <code>sayHi</code> passing <code>kitty</code> as context.</p> <p>Now <code>kitty = new Animal</code> (this is called a closure actaully since you're accessing parent function's variable), so <code>this</code> -> <code>Animal</code> </p> <pre><code>(function($, Animal){ // create a new instance of Animal, assign it to local variable kitty var kitty = new Animal; // assign sayHi to kitty object kitty.sayHi = function(){ console.log(this); console.log('says meow'); } // $() shortcut that says run this code on DOM ready $($.proxy(function(){ // this proxy almost does nothing as we do not refer to this object insdie it // says on click of js_Test, call kitty.sayHi with context = kitty $('#js_test').click($.proxy(kitty.sayHi, kitty)); }, kitty)) })(jQuery, Animal); </code></pre> <p>So when the click handler is called, its actually <code>Animal.sayHi</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. 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.
 

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