JavaScript bind, currying and arrow functions

How many times have you written code like this:
var foo = { makeRequest: function () { $.get(‘/foo’, function (result) { this.update(result); }); ); }, update: function (data) { /* … */ } }; //somewhere later in the code foo.makeRequest(); Only to ha…


This content originally appeared on Posts on LINQ to Fail and was authored by Posts on LINQ to Fail

How many times have you written code like this: var foo = { makeRequest: function () { $.get('/foo', function (result) { this.update(result); }); ); }, update: function (data) { /* ... */ } }; //somewhere later in the code foo.makeRequest(); Only to have it poo itself saying that this.update is not a function? Maybe it was with an event handler not an AJAX request, all in all it’s the same problem, you tried to use something and JavaScript changed the value of this on you.


This content originally appeared on Posts on LINQ to Fail and was authored by Posts on LINQ to Fail


Print Share Comment Cite Upload Translate
APA
Posts on LINQ to Fail | Sciencx (2023-11-28T22:03:14+00:00) » JavaScript bind, currying and arrow functions. Retrieved from https://www.scien.cx/2013/07/05/javascript-bind-currying-and-arrow-functions/.
MLA
" » JavaScript bind, currying and arrow functions." Posts on LINQ to Fail | Sciencx - Friday July 5, 2013, https://www.scien.cx/2013/07/05/javascript-bind-currying-and-arrow-functions/
HARVARD
Posts on LINQ to Fail | Sciencx Friday July 5, 2013 » JavaScript bind, currying and arrow functions., viewed 2023-11-28T22:03:14+00:00,<https://www.scien.cx/2013/07/05/javascript-bind-currying-and-arrow-functions/>
VANCOUVER
Posts on LINQ to Fail | Sciencx - » JavaScript bind, currying and arrow functions. [Internet]. [Accessed 2023-11-28T22:03:14+00:00]. Available from: https://www.scien.cx/2013/07/05/javascript-bind-currying-and-arrow-functions/
CHICAGO
" » JavaScript bind, currying and arrow functions." Posts on LINQ to Fail | Sciencx - Accessed 2023-11-28T22:03:14+00:00. https://www.scien.cx/2013/07/05/javascript-bind-currying-and-arrow-functions/
IEEE
" » JavaScript bind, currying and arrow functions." Posts on LINQ to Fail | Sciencx [Online]. Available: https://www.scien.cx/2013/07/05/javascript-bind-currying-and-arrow-functions/. [Accessed: 2023-11-28T22:03:14+00:00]
rf:citation
» JavaScript bind, currying and arrow functions | Posts on LINQ to Fail | Sciencx | https://www.scien.cx/2013/07/05/javascript-bind-currying-and-arrow-functions/ | 2023-11-28T22:03:14+00:00
https://github.com/addpipe/simple-recorderjs-demo