Quick actions

cmd+k|ctrl+k

Navigation

Languages

如何合并两个函数?

Snippet info

Language

JavaScript

Visibility

public

Author

pheker

Created

2017-07-20T06:58:28Z

Updated

2017-07-20T10:23:48Z


Function.prototype.getName = function(){
    return this.name || this.toString().match(/function\s*([^(]*)\(/)[1]
}

function a(){
    
}
a.prototype.alias = "a_name";
a.prototype.getAlias = function(){
    return this.alias;
}
a.tobe = "number one";


function b(){
    
}

function getInfo(){
    var argLen = arguments.length;
    for(var i=0;i<argLen;i++){
        console.log("\n-----------------------------\n")
        var fn = arguments[i];
        if(Object.prototype.toString.call(fn)!='[object Function]'){
            throw "the parameters must be function";
        }
        console.log("name:\t"+fn.getName());
        for(var p in fn){
            console.log("property:"+p+"="+fn[p]+",\tprototype:"+JSON.stringify(fn.prototype));
        }
    }
   
}
console.log(JSON.stringify({getInfo:getInfo}))
console.log(a.prototype.getAlias)
getInfo(a,b);




INFO