Explanation asked about the value of 'this' in Javascript [duplicate]
This question already has an answer here: How does the “this” keyword work? 22 answers I have this class in Javascript: return function (settings) { var items = [], formHelper = new FormHelper(items), that = this; this.currentItem; this.initialize = function () { settings.listFn().then(function (response) { angular.copy(response, items); if (response.length > 0) { that.setCurrentItem(response[0]); } }); } } In the initialize method, I use a promise. When this promised is finished, the anonymous function is executed. Within the function you see the use of that , which is declared at line 4.