jquery - Javascript 'this' Problem -


Why are setting 'm' and 'it' unsure when setTimeout calls it an anonymous callback?

var gMyObj = new MyObj (); GMyObj.myFunc (); Function MyOuse () {this.myFunc = function () {var me = this; Warning (me.constructor); // defined setTimeout (function (me) {warning (me.constructor); // undefined}, 100); }; }

Resolution: The selected answer is correct, thanks. My question was that the way I was simplifying the real problem, the way in which jQuery refers to the relevant DOM element in order to modify the (click) inside this 'click' To catch, a new class was created, 'm', and was trying to pass it in the click method. All I needed to do was just use 'me' inside the click event, and reference it in the context of closing. Failed to pass 'me' (nearby) to the nearest reason, for this reason that he failed in this example, i.e., click () he was not expecting

< / P>

  function () { 

And you can go.

as' why? 'Part, you are defining an anonymous operation that takes the argument called me when setTimeout () states that the function does not give any argument, which means me will be undefined. Allows to appear inside the me function, defined before removing the argument from me from the argument list.


Comments