简体   繁体   中英

Why is this function being called?

I am trying to modify some behavior of a framework's JavaScript. In IE10's developer tools under the View source drop down, there is a folder called Dynamic Scripts . (Maybe someone could explain what Dynamic Scripts are?) And there is the following code under Function code (1089)
This is the code:

function anonymous() {
var f=arguments.callee; return f._func.apply(f._owner, arguments);
}

And the first entry of the call stack is

Function code, Function code (1089), line 2

This line gets executed several times. But I don't know why.

Who calls this line?

The anonymous function call does not mean a function called anonymous . It is actually a name that is used to classify unnamed functions, like this one:

var anUnnamedFunc = function() {
    return true;
};

If you referenced this function in a watch or console output, it would be dumped as an anonymous function. To define a function that isn't anonymous, you would use:

var aNamedFunc = function namedFunction() {
    return true;
};

The function being called in question, looks a lot like a bind function. That is a wrapper function used to create a function that binds arguments and or context to another function. However, this version uses some sort of private property mechanism to bind arguments:

var bind = function() {
    var f = arguments.callee;
    return f._func.apply(f._owner, arguments);
};

I actually don't see what this sort of function would be used for, so wonder if it is just an anomaly of the IE debugger. Try using a different browser and see if that function appears in the profile report.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM