I have a file.js
like this:
JavaScript
x
19
19
1
// TICautocapture.js
2
3
var TICautocapture = (function(){
4
var lib = { }
5
var error_handler;
6
var handleError = (error_code, error_callback) => { }
7
function autocapture(container, options){ }
8
9
return autocapture;
10
})();
11
12
if(window.jQuery){
13
(function($){
14
$.fn.autocapture = function(options){
15
TICautocapture(this.attr('id'), options);
16
}
17
}(jQuery));
18
}
19
My question is (I’m not sure how jQuery works at this)
- What is doing the last
if
statement?
My idea is to convert that all function in a React util like
JavaScript
1
6
1
const TICautocapture = () => {
2
// all the code inside
3
}
4
5
export default TICautocapture;
6
And to use its methods and values, but I don’t understand what it is doing that last part that I said. Any help please.
Advertisement
Answer
What is doing the last
if
statement?
It is simply checking if jQuery exists in the window object since the $
alias is accessed in the following instruction. This is an example of IFEE. The code checks if window.jQuery
exists, then passes it to the IFEE and catches it as $
in the parameter for that function.
I hope this answered your question.