This question has already been answered:

Good day, it may be a silly question, but the hunt is beautiful, do not scold too much :)

There is, say, the following code, and there is also a question:

function OrderAjax(param) { this.emptyDetailPicture = param.emptyDetailPicture; this.jsData = param.jsData; } OrderAjax.prototype = { constructor: OrderAjax, renderBasket: function() { $.each(this.jsData['items'], function(index, item) { //Как вот сюда красиво достать значение this.emptyDetailPicture? }); } } 

Thank you in advance :)

Reported as a duplicate at Grundy. javascript Jan 4 '17 at 9:45 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    2 answers 2

     class OrderAjax { constructor({emptyDetailPicture, jsData}){ this.emptyDetailPicture = emptyDetailPicture; this.jsData = jsData; } renderBasket(){ $.each(this.jsData['items'], (index, item) => { console.log(this.emptyDetailPicture); // все дело в стрелочной функции которая сохраняет контекст объявления }); } } 
    • Great, thanks :) - k0mar

    es5

     OrderAjax.prototype = { renderBasket: function() { $.each(this.jsData['items'], this._ProcessData.bind(this)); }, _ProcessData: function(index, item){ console.log(this.emptyDetailPicture); } }