How can I understand the preliminary concepts of jquery

From time to time, whenever I see any code for the plugin, I could not understand 80% of the code. I know some jquery and successfully, but I could not find these ways to do what they did in the plugins.

usually the code I do in 10 lines, they make a few shortcuts and end in 1 using advanced methods.

for example, this is the code from jQuery fileupload plugin

// Callback for uploads start, equivalent to the global ajaxStart event: start: function (e) { var that = $(this).data('fileupload'); that._transition($(this).find('.fileupload-progress')).done( function () { that._trigger('started', e); } ); }, 

I have no idea what happens, why the function name begins with an underscore. what has been done and all this.

Where can I find this material fully explained by examples so that I can also reduce my code

+4
source share
1 answer

Here is how I understand it:

start is a callback function, as stated in the Callback for uploads start, equivalent to the global ajaxStart event

var that is the equation in:

Returns the value in the named data store for the item specified by jQuery.data (item, name, value) or the full data store for the item.

When the that variable is set, a function call appears with the name _transition , which, I believe, is some extension of the Ajax call, since we later call the done function. The author probably owns the work, so you will need to look for the code.

This function gets a list of parameter objects returned by $(this).find('.fileupload-progress') .

Finally, we call the done function, which I assume is equal to eq. jQuery.ajax (). done () called after a sucessfull Ajax request. Inside made another callback for anonymous function

 .done(function(){ .... }) 

If another function called _trigger was launched with the string started and the callback event of the main function start e .

And answer your last question:

Where i can find that sort of stuff fully explained with examples so that i can also reduce my code?

The truth is that without writing out your own things, you probably will never know about it. Experience and coding is the key. When looking for specific solutions, you will learn, for example, new things like this. So keep coding!

+2
source

Source: https://habr.com/ru/post/1439763/


All Articles