javascript - 将数据从一个函数传递到另一个函数

时间:2015-02-21 01:19:16

标签: javascript jquery function

我有两个功能。我想要这个功能:

function indentSpace(s, n){
  return ((new Array(n+1)).join(s));
}

要从此功能获取它的参数,同时允许此功能继续:

 function onHandle(line, report) {
  var input = $.trim(line);
  if (parensBalanced(input) == false) {
    indentSpace('.',input.length);
    controller.continuedPrompt = true;
  } else if (parensBalanced(input) == true) {
    controller.continuedPrompt = false;
    if (doCommand(input)) {
      report();
      return;
    }

    ...

  }
}

这里使用第一个函数,作为continuedPromptLabel的值:

$(document).ready(function() {
controller = $("#console").console({
  continuedPromptLabel: indentSpace,
  completeHandle: onComplete,
  });
});

我已经尝试了几种不同的方式,似乎一旦我得到indentSpace的值,它也会在其包含的函数中返回该值 - 并打破其他东西。

干杯!

1 个答案:

答案 0 :(得分:0)

所以你希望indentspace从onHandle异步调用它的参数上有一个闭包,这样onHandle可以自由运行,但是你想要那些带有这些参数的indentspace在别处使用吗?我不认为这是可能的。