For example, we want to set a method in a class can be stored in a class variable according to the call into a method, and so on, when needed, by accessing the class variable to be obtained.
Usually if we generate an instance
such as: Var temp=new topnettree ();
If we pass a method by setting the property, we find that the content of a function is passed in, not the function name.
such as Temp.fileaction=fntest; Fntest is a function
So I wrote a method to implement this function.
Judging incoming content by arguments:
The following functions are implemented:
The incoming content is empty and no content is executed
Passing in a parameter, it means a function with no parameters
When multiple parameters are passed in, the first parameter-bit function name is followed by each argument.
Copy Code code as follows:
1 topnettree.prototype.setfileaction=function () {
2 var fnname,fnargs= "";
3 if (arguments.length==0) {
4 return 0;
5}else if (arguments.length==1) {
6 fnname=arguments[0];
7}else{
8 fnname=arguments[0];
9 for (Var i=1;i<arguments.length;i++) {
Ten fnargs+= "," +arguments[i];
11}
Fnargs=fnargs.replace (",", "");
13}
14
This.fileaction=fnname+ "(" +fnargs+ ")";
16}