简体   繁体   English

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

[英]javascript - pass data from one function to another

I have two functions. 我有两个功能。 I want this function: 我想要这个功能:

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

To get it's parameters from this function, while allowing this function to continue: 要从此函数获取它的参数,同时允许此函数继续:

 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;
    }

    ...

  }
}

So that the 1st function gets used here, as the value for continuedPromptLabel : 这样第一个函数在这里使用,作为continuedPromptLabel的值:

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

I've tried it several different ways, and it seems that once I get a value for indentSpace , it also returns that value in its containing function - and breaks other stuff. 我已经尝试了几种不同的方式,似乎一旦我得到indentSpace的值,它也会在其包含函数中返回该值 - 并打破其他东西。

Cheers! 干杯!

So you want indentspace to essentially have a closure on its parameters from being called asynchronously from onHandle, such that onHandle is running freely, but then you want that indentspace with those parameters to be used elsewhere? 所以你希望indentspace基本上有一个关于它的参数的闭包从onHandle异步调用,这样onHandle可以自由运行,但是你想要那些带有这些参数的indentspace在别处使用吗? I don't think that's possible. 我不认为这是可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将Javascript数据从一个函数传递到另一个函数 - Pass Javascript data from one function to another javascript将元素从一个函数传递到另一个函数 - javascript pass element from one function to another 如何将json数据从一个JavaScript函数传递到另一个JavaScript函数? - How to pass json data from one javascript function to another javascript function? 如何将数据从一个功能传递到另一个功能? - how to pass data from one to another function of? 如何在javascript中将变量从一个函数传递给另一个函数 - how to pass variable from one function to another function in javascript 如何在JavaScript中将局部变量从一个函数传递给另一个函数 - how to pass local variable from one function to another function in javascript 如何在原版 JavaScript 中将其从一个 function 传递到另一个 function? - How to pass this from one function to another function in vanilla JavaScript? 将OnClick事件中的参数从一个Javascript函数传递给另一个Javascript函数 - Pass Parameter From OnClick Event from one Javascript Function to Another 将变量从一个JavaScript回调匿名函数传递给另一个 - Pass variable from one JavaScript callback anonymous function to another 如何将变量从一个 function 传递到另一个 Javascript? - How to pass variable from one function to another Javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM