0
<script type="text/javascript"> 
var DYN_WEB = DYN_WEB || {};
DYN_WEB.Util = (function( Ut ) {
    Ut.getResult = function ( cl, tag, el ) {
    console.log(arguments)
    }
return Ut;
})( DYN_WEB.Util || {} );
var links = DYN_WEB.Util.getResult('show-hide');
</script>  

In chrome->console, it shows: ["show-hide"]

Question:

when script goes to this line:DYN_WEB.Util, did not reach var links yet, why console.log(arguments) can still outputs ["show-hide"] , not undefined?

2 Answers 2

1

You could add some extra lines if you want to understand the execution flow. The getResult function is called on the links line. Try this:

var DYN_WEB = DYN_WEB || {};
DYN_WEB.Util = (function (Ut) {
    Ut.getResult = function (cl, tag, el) {
        console.log(arguments)
    }
    return Ut;
})(DYN_WEB.Util || {});
console.log("before links");
var links = DYN_WEB.Util.getResult('show-hide');
console.log("after links");

The console output will be:

before links
["show-hide"]
after links 
Sign up to request clarification or add additional context in comments.

Comments

0

DYN_WEB.Util is a function and will not execute itself. So you are wrong at the point that it not reach at the var links.

First it will reach at the var links from where it will call to DYN_WEB.Util function and it will pass the arguments that you are using.

So the flow of calling will be first it call to var links from where it call to DYN_WEB.Util function that it initialize above and then execute the console.log.

And it output the show-hide.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.