[英]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.