The method of obtaining external function name in JS class and code _js object oriented

Source: Internet
Author: User
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}

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.