A
A
alx19872016-05-22 09:47:47
JavaScript
alx1987, 2016-05-22 09:47:47

Why does loading the config work every other time?

Hello, please help. I can't understand why App.config is loaded every other time.
Intermittent error: Uncaught TypeError: _this.config.done is not a function

var App = function() {
  this.init();
};
App.prototype = {
  items: $.getJSON("/items.json", function(data) {
    App.items = data;
  }),
  config: $.getJSON("/config.json", function(data) {
    App.config = data;
  }),
  init: function() {
    var _this = this;
    
    _this.items.done(function() {
      _this.config.done(function() {
        _this.initConfig();
      });
    });
  },
  ...............
}, $(document).ready(function() {
    App = new App
});

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alx1987, 2016-05-22
@alx1987

Cured like this:

var App = function() {
  this.init();
};
App.prototype = {
  items: $.ajax({
    url: "/items.json",
    dataType: "json",
    async: false
  }),
  config: $.ajax({
    url: "/config.json",
    dataType: "json",
    async: false
  }),
  init: function() {
    var _this = this;
    
    _this.items.done(function(data) {
      _this.items = data;
    });
    _this.config.done(function(data) {
      _this.config = data;
      _this.initConfig();
    });

But I still can't figure out why... now ITEMS and CONFIG are requested sequentially, and in the first variant at the same time ... but I have it clearly indicated - we request ITEMS, when done, we request CONFIG, but in the console you can still see that they are loaded in parallel

C
coderisimo, 2016-05-22
@coderisimo

In general, items and config are called right when you create an object))))
you need to write like this

items: function(){   
 $.getJSON("

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question