我有一个带有局部变量的递归函数。它在特定条件下调用自己。局部变量需要更新,但每次调用都会创建一个特定于当前函数作用域的新局部变量。我怎样才能到达局部变量来访问所有递归循环而不是创建一个新循环?像 __Callee.varname 这样的东西?
代码是:
var addAttribute = function(object,elem)
{
var attributes = [];
// only attribute without values
if ( object instanceof Array )
{
for ( var value in object )
{
attributes.push(object[value]);
}
}
// attribute with values
else if ( object instanceof Object )
{
for ( var key in object )
{
if ( object[key] instanceof Array )
{
addAttribute(object[key],elem);
}
else
{
attributes.push(key+'=\''+object[key]+'\'');
}
}
}
// Only one attribute
else if ( typeof object …Run Code Online (Sandbox Code Playgroud)