How does the jQuery.proxy() work in this situation? -


I try to understand To be precise, study method $. Proxy () Unless I found this script, everything was clear:

  (function ($, export) {var mod = function () {}; mod.fn = mod Prototype; mod.fn.proxy = function (function) {return $. Proxy (function, this);}; mod.fn.load = function (func) {$ (this.proxy (func));} export; controller = Modern;}) (jQuery, window); (Function ($, controller) {var mod = new controller; mod.toggleClass = function (e) {this.view.toggleClass ("over", e.data);}; mod.load (function () {see = $ ("#view"); this.view.mouseover (this.proxy (this.toggleClass); this.view.mouseout (this.proxy (this.toggleClass));});}) (jQuery, controller );   

And I do not understand how $ .proxy () works in this part:

  mod.fn.load = function (func ) {$ (this.proxy (function)); // Why is this an object converted to jQuery? }; Can anyone explain how it works?   

This is not a jQuery object, $ (this.proxy (func)); As a domain handler, entering the function passed to the load method so that even if the code is called before the dome is ready, the callback function delayed until the dame was ready. It happens. If the DOM is already in the ready state, then the callback is executed without any delay.

  mod.fn.load = function (func) {console.log ('inside load') $ (this .proxy (function)); Console.log ('Exit Load')};   

Demo:

  mod.fn.load = function (func) {var itself = this; // DOM Ready Callback $ (function () {func.call (self);}); };   

Demo:


If you are not doing this then there is a possibility that the script will fail such as

  Mod.fn.load = function (func) {var itself = this; Console.log ('load inside'); Func.call (self); Console.log ('exit load')};   

Demo:

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -