如果我们有
function parent(){
function a(){
return 'i am a';
}
function b(){
return 'i am b';
}
function c(e,f){
console.log(e+f);
}
c(a(),b());
}
任何获取嵌套函数名称的内置方法:a,b,c。比如:
parent.closures()
// ['a','b','c']
}
DEMO
Function.prototype.closures=function() {
var that=this,fn = function(r) {
//see demo==> to reduce non-functional code
};
return this.toString().split("n").filter(function(d) {
return d.indexOf('function ') !== -1
}).map(fn).filter(function(f) {
return f !== that.name;
})
};
:
parent.closures()
// ['a','b','c']