The method is saved in the class variable, and can be obtained through the class variable when needed.
Generally, If we generate an instance
For example, var temp = new TopnetTree ();
If we pass in a method by setting attributes, we will find that the content of a function is passed in, not the function name.
For example, temp. fileAction = fnTest; // fnTest is a function.
So I wrote a method to implement this function.
Determine the input content through arguments:
Implement the following functions:
The input content is blank and NO content is executed.
Input a parameter to indicate a function without Parameters
If multiple parameters are input, the first parameter is used as the function name, followed by each parameter.
Reference content is as follows:
TopnetTree. prototype. setFileAction = function (){
Var fnName, fnArgs = "";
If (arguments. length = 0 ){
Return 0;
} Else if (arguments. length = 1 ){
FnName = arguments [0];
} Else {
FnName = arguments [0];
For (var I = 1; I <arguments. length; I ++ ){
FnArgs + = "," + arguments [I];
}
FnArgs = fnArgs. replace (",","");
}
This. fileAction = fnName + "(" + fnArgs + ")";
} |