DEV Community

Discussion on: I am not able to understand 'factory'

Collapse
 
webjayant profile image
Jayant Raj Singh

I understand what are you saying here.
Here is the whole code.

The first IIFE is taking factory as an argument, but where is the factory coming from.

jQuery does the same

Collapse
 
somedood profile image
Basti Ortiz

From my best efforts to understand the code, I think it has misplaced a parenthesis after the } in line 26. Adding the missing parenthesis and fixing the respective closing parentheses at line 163 should reveal that the factory function is defined by the argument to the first IIFE.

Honestly, I question that this code even works. The way the code has been formatted is so strange and obscure. I don't even know if it's a syntax error or just poor formatting.

Thread Thread
 
webjayant profile image
Jayant Raj Singh

The problem is with the way the code is formatted.


;(function(factory){
    ...
    ...
}(function (){
    ...
    ...
}))

the code formatted like above thus there is no error and the code works fine.

The only problem is that this type of formatting creates a lot of confusion (It took me two days, and your help in deciphering it)

this would have been a better approach

function factory (){
    ...
    ...
}

(function(factory){
    ...
    ...
})()
Thread Thread
 
somedood profile image
Basti Ortiz

Yup, agreed. Perhaps you could submit a pull request to format the code. That way, you can help people who are just as curious of the code understand it better. Contributions are always welcome (and needed) in the open-source world.