Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing 'this' inside a callback inside an object literal
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/13996794/javascript-prototype-this-issue">Javascript prototype ‘this’ issue</a> </p> </blockquote> <p>I have an event listener which of course calls a method on an event. This method tries unsuccessfully to hold a reference to the holding objects this so that it can access other properties of the object.</p> <p>There is a single comment denoting where the behavior is not understood. this_hold.Name is not accessible there as I thought it would be.</p> <pre><code>/*MUserExist ** ** ** */ $A.module({ Name: 'MUserExist', S: { ClientStorage: SClientStorage, ComMessage: SComMessage, ComText: SComText, DynSma: SDynSma, DynTwe: SDynTwe, DynArc: SDynArc, AniMorphLabel: SAniMorphLabel, AniFlipPage: SAniFlipPage }, E: { but: $A('#ue_but')[0], text: $A('#ue_go')[0], form: $A('#ue_fo')[0], check: $A('#ue_check')[0] }, J: { box: $('#ue_box') }, init: function () { var pipe = {}, this_hold = this; this.J.box.draggable(); this.E.but.addEventListener("click", function () { pipe = $A.definePipe(this_hold.Name); $A.machine(pipe); }, false); this.E.text.addEventListener("keypress", this.enter, false); this.S.AniMorphLabel.run(["ue_email", "ue_email_lab", "ue_go", "ue_pass_lab" ]); }, enter: function (event) { var pipe = {}, this_hold = this; if (event.keyCode === 13) { pipe = $A.definePipe(this_hold.Name); // fails here what does 'this' point to? $A.machine(pipe); event.preventDefault(); } }, pre: function (pipe) { var form_elements = this.E.form.elements, text_object = new this.S.ComText(form_elements); pipe.enter = this.enter; if ($A.Un.get('load') === '1') { if (!text_object.checkFull()) { pipe.type = 'empty'; return this.S.ComMessage.message(pipe); } if (!text_object.checkPattern('email')) { pipe.type = 'email'; return this.S.ComMessage.message(pipe); } if (!text_object.checkPattern('pass')) { pipe.type = 'pass'; return this.S.ComMessage.message(pipe); } } pipe.page = text_object.getArray(); pipe.proceed = true; pipe.page.remember = this.E.check.checked; return pipe; }, post : function (pipe) { if (pipe.proceed === true) { this.S.ComMessage.resetView('ue_email'); this.S.ComMessage.resetView('ue_go'); this.S.ClientStorage.setAll(pipe.server.smalls); this.S.DynSma.run(pipe.server.smalls); this.S.DynArc.run(pipe.server.arcmarks); this.S.DynTwe.run(pipe.server.tweets); this.S.AniFlipPage.run('ma'); } else { return this.S.ComMessage.message(pipe); } } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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