e5中一般的对象继承,无论是浅还是深对于函数对象都是引用,本例子根据toString()和new Function()及eval动态执行字符串 实现无污染加强版深继承
var func=function(a,b,c){
alert(a+b+ c);
}
var str=func.toString();
var str1=str.slice(str.indexOf("(")+1,str.indexOf(")"));
var str2=str.slice(str.indexOf("{")+1,str.lastIndexOf("}"));
var ary1=str1.split(",");
var ary=[];
for(var i=0;i<ary1.length;i++){
ary.push("'"+ary1[i]+"'");
}
ary.push("'"+str2.replace(/\n\r/g,"")+"'");
var strResult=ary.join(",");
console.log(strResult)
var result=eval("new Function("+strResult+")");
result(1,2,3)