Javascript/jQuery order of operations -


Before I get conditional I have to do an I:

  1. To see this Check for whether the data (the older old array of numbers) has already been loaded.
  2. If it does not get it and it is not loaded in my all_data object.
  3. Plot data (or this warning in this case)

Here is the code (many details have been snatched to readable

  var all_data = {}; function get_data (name, get rid) {if (! All_data [name]) {return $ .get ('/ data.json', {'name': name}, function (data) {All_data [Name] = data;}, "json");} and {return}} function load_file (name, escape) {if (get_data (name, escape)) {warning (all_data [name])}}  

What happens to the above code is that when I execute get_data, it is immediately "undefined" alert Because jQuery.get is returning an (not completed) requested object. At this point the entry is all_data [name] is undefined. If I receive the request of ~ 5s, and I run the code again, then "[object] Object] "will be warned to have data loads. I realized that I can put the function in just $ $. Callback and give it another statement, but this will no longer be normalized any thoughts?

Pass the goods that need to be done or the data is loaded as a callback function on load_file This is a The normal solution is because if the data is already available, your callback is applied immediately, otherwise it is applied when the data is available.

Also try to use the global condition all_data in as much as possible, as much as possible, as much as possible. That would be possible.

There are alternative approaches to providing a fluent interface, but what are they doing with the data after loading without it, it is difficult to suggest one.

  function load_file (name, get rid, FN) {get_data (name, redemption, FN); } Load_file ("..", "..", function () {alerts (all_data [".."]);}); The  

get_data function is made:

  function get_data (name, redemption, FN) {if ( ! All_data [name]) {return $ .get ('/ data.json', {'name': name}, function (data) {all_data [name] = data; fn ();}, "json"); } Else {fn (); }}  

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -