1
These days, I asked a question here at Sopt and the boy answered me with a code, creating a function within another function, something simple, but I didn’t use it, and I started to implement.
function QuantosEmEstoqueAbrir(){
$j('.availability-only').attr("style", "transform: translate(0);");
function QuantosEmEstoqueFechar(){
$j('.availability-only').attr("style", "transform: translate(300px);");
} setTimeout(QuantosEmEstoqueFechar, 10000);
}
setTimeout(QuantosEmEstoqueAbrir, 10000);
This is a "mini notification" I made to a store system, and it’s working fine!
But my question is this, looking at the code mentioned above, which the boy gave me in response:
function domReady(cb) {
(function checkDomReady() {
var state = document.readyState;
if (state == 'loaded' || state == 'complete') cb();
else setTimeout(checkDomReady, 200);
})();
};
He used his function between parentheses. Why?
(function checkDomReady() {
var state = document.readyState;
if (state == 'loaded' || state == 'complete') cb();
else setTimeout(checkDomReady, 200);
})
Related or duplicate About (Function(){ ... }()) and callThis()
– Jéf Bueno
Related or duplicate What is the usefulness of Exclamation Mark (!) before declaring functions in Javascript?
– Jéf Bueno
Related or duplicate What’s the difference between creating a module normally and creating a module within a function?
– Jéf Bueno