Method for obtaining external function names using JS scripts (Appendix: Code)

Source: Internet
Author: User

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 + ")";
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.