This question has already been answered:
I get after calling the function __self.getJSonData () - empty object {} . Maybe someone will find an error / problem.
Here is the code
(function() { function Calculator() { var __self = this; this.render = function() { console.log(__self.getJSonData()); } } //Получить данные из JSON Calculator.prototype.getJSonData = function() { var ajax = new XMLHttpRequest(); var url = 'data.json'; var self = this; var data = {}; ajax.onreadystatechange = function() { if (ajax.readyState == 4 && ajax.status == 200) { returnData(ajax.responseText); } }; ajax.open("GET", url, true); ajax.send(); function returnData(json) { data = JSON.parse(json); console.log(data); } return data; }; window.calculator = new Calculator(); calculator.render(); })();
getJSonDatareturned much earlier than the asynchronousajax.onreadystatechange, within which you assigndatanon-empty value - Igor