[英]JavaScript Function like Variable
I want to use this function to call between results:我想用这个 function 在结果之间调用:
Working Result:工作结果:
function flag1(newflag){
console.log('This is'+newflag+' Got it?')
}
flag1('My_Flag')
// Result: This is My Flag Got it?
Not showing anything / Not Working:不显示任何内容/不工作:
function flag2(newflag){
'This is '+newflag+' Got it?'
}
flag2('My_Flag')
// Result: <Nothing>
I know 2nd Example is Dumb but what else can i think of?我知道第二个例子是愚蠢的,但我还能想到什么? My Goal is to send this in response with other stuff like above: This is My Flag Got it?
我的目标是发送此消息以响应上述其他内容:这是我的旗帜 明白了吗?
For example:例如:
res.send('Blah Blah Blah '+flag2('My_Flag')+' Blah Blah Blah')
res.send('Blah Blah Blah'+flag2('My_Flag')+' Blah Blah Blah')
Expected Result:预期结果:
Blah Blah Blah My_Flag Blah Blah Blah
Blah Blah Blah My_Flag Blah Blah Blah
This Question is based on Expressjs, but others might be able to help too这个问题基于 Expressjs,但其他人也可以提供帮助
PS: This is for CTF or capture the flag nothing about countries these will be diffrent and unique everywhere thats why im using functions... PS:这是针对 CTF 或捕获国旗的,与国家无关,这些在任何地方都是不同的和独特的,这就是我使用函数的原因......
In your second example 'This is '+newflag+' Got it?'
在您的第二个示例
'This is '+newflag+' Got it?'
creates a string.创建一个字符串。
That is all it does.这就是它所做的一切。
It doesn't pass it to another function (like console.log
or res.send
).它不会将它传递给另一个 function (如
console.log
或res.send
)。
It doesn't assign it to a variable.它不会将其分配给变量。
It doesn't assign it to a property of an object.它不会将其分配给 object 的属性。
It doesn't return
it so it can be used on the left hand side of flag2('My_Flag')
(not that you have anything on the left hand side of that function call … although you do in the later example: res.send('Blah Blah Blah '+flag2('My_Flag')+' Blah Blah Blah')
).它不会
return
它,因此可以在flag2('My_Flag')
的左侧使用(并不是说您在该 function 调用的左侧有任何内容……尽管您在后面的示例中这样做: res.send('Blah Blah Blah '+flag2('My_Flag')+' Blah Blah Blah')
)。
Since you don't do anything, the string is thrown away immediately after it is created (unless the compiler optimises the string creation away entirely).由于您不执行任何操作,因此字符串在创建后立即被丢弃(除非编译器完全优化字符串创建)。
If you want to do something with the string, then you have to write code which does that.如果您想对字符串做某事,那么您必须编写执行此操作的代码。
This Worked:这有效:
function flag2(newflag){
return (newflag);
}
res.send('Blah Blah Blah '+flag2('My_Flag')+' Blah Blah Blah')
Its so simple, forgot return太简单了,忘记返回了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.