scope

PowerShell - execute script block in specific scope

一世执手 提交于 2021-02-07 12:10:55
问题 I am trying to implement RSpec/Jasmine like BDD framework in Powershell (or at least research the potential problems with making one). Currently I am having problems with implementing simple before/after functionality. Given $ErrorActionPreference = "Stop" function describe() { $aaaa = 0; before { $aaaa = 2; }; after { $aaaa; } } function before( [scriptblock]$sb ) { & $sb } function after( $sb ) { & $sb } describe the output is 0, but I would like it to be 2. Is there any way to achieve it

Variable declared and not used in conditional statement

Deadly 提交于 2021-02-07 08:43:52
问题 I declare some variables ( offsetI and limitI ) outside of a conditional statement. Inside the conditional statement I am trying to assign them values, then use those values for a query after the conditional statement. var ( number, size, offset, limit string offsetI, limitI uint64 ) // Get the string values for number, size, offset, and limit // ... if size != "" { // Parse the number value numberI, err := strconv.ParseUint(number, 10, 64) if err != nil {...} // Parse the size value limitI,

Variable declared and not used in conditional statement

安稳与你 提交于 2021-02-07 08:41:24
问题 I declare some variables ( offsetI and limitI ) outside of a conditional statement. Inside the conditional statement I am trying to assign them values, then use those values for a query after the conditional statement. var ( number, size, offset, limit string offsetI, limitI uint64 ) // Get the string values for number, size, offset, and limit // ... if size != "" { // Parse the number value numberI, err := strconv.ParseUint(number, 10, 64) if err != nil {...} // Parse the size value limitI,

Variable declared and not used in conditional statement

对着背影说爱祢 提交于 2021-02-07 08:39:30
问题 I declare some variables ( offsetI and limitI ) outside of a conditional statement. Inside the conditional statement I am trying to assign them values, then use those values for a query after the conditional statement. var ( number, size, offset, limit string offsetI, limitI uint64 ) // Get the string values for number, size, offset, and limit // ... if size != "" { // Parse the number value numberI, err := strconv.ParseUint(number, 10, 64) if err != nil {...} // Parse the size value limitI,

Delegates and variables scope

ぐ巨炮叔叔 提交于 2021-02-07 08:19:04
问题 I have the following code: public void SetMove(Position3D pos, float time, float linearity, bool relative) { ExecuteOnActiveClients(delegate(NeuroClient client) { client.Engine.GetProcAnimation(name).SetMove(pos, time, linearity, relative); }, true, true); } Where ExecuteOnActiveClients pushes the delegate in a queue, consumed asynchronously, and has the following signature: void ExecuteOnActiveClients(ClientDelegate action, Boolean parallel, Boolean wait, Boolean lockClient) I have a lot of

Delegates and variables scope

牧云@^-^@ 提交于 2021-02-07 08:18:30
问题 I have the following code: public void SetMove(Position3D pos, float time, float linearity, bool relative) { ExecuteOnActiveClients(delegate(NeuroClient client) { client.Engine.GetProcAnimation(name).SetMove(pos, time, linearity, relative); }, true, true); } Where ExecuteOnActiveClients pushes the delegate in a queue, consumed asynchronously, and has the following signature: void ExecuteOnActiveClients(ClientDelegate action, Boolean parallel, Boolean wait, Boolean lockClient) I have a lot of

C++ variable scope

只谈情不闲聊 提交于 2021-02-05 12:37:38
问题 I have C++ code different output compared to what I expected, I hope to understand how it's executed #include <iostream> #include <string> int x = 8; class A { public: A() { int x = 5 ; } void print (int x = 4) { std::cout << "the scope variable"<< ::x << "passed variable" << x; } }; int main() { A a; a.print(7); } I expected to be 5 and 7 but the result is 8 and 7 回答1: If you expected the output 5 and 7 then the constructor has to deal with the global variable instead of the local variable.

C++ variable scope

我们两清 提交于 2021-02-05 12:36:32
问题 I have C++ code different output compared to what I expected, I hope to understand how it's executed #include <iostream> #include <string> int x = 8; class A { public: A() { int x = 5 ; } void print (int x = 4) { std::cout << "the scope variable"<< ::x << "passed variable" << x; } }; int main() { A a; a.print(7); } I expected to be 5 and 7 but the result is 8 and 7 回答1: If you expected the output 5 and 7 then the constructor has to deal with the global variable instead of the local variable.

C++ variable scope

柔情痞子 提交于 2021-02-05 12:36:13
问题 I have C++ code different output compared to what I expected, I hope to understand how it's executed #include <iostream> #include <string> int x = 8; class A { public: A() { int x = 5 ; } void print (int x = 4) { std::cout << "the scope variable"<< ::x << "passed variable" << x; } }; int main() { A a; a.print(7); } I expected to be 5 and 7 but the result is 8 and 7 回答1: If you expected the output 5 and 7 then the constructor has to deal with the global variable instead of the local variable.

Retrieving values from Execution Contexts in JavaScript

≡放荡痞女 提交于 2021-02-05 11:21:11
问题 var value = 10; var outer_funct = function(){ var value = 20; var inner_funct = function(){ var value = 30; console.log(value); // logs 30 console.log(window["outer_funct"]["value"]); // What I would like to log here is the value 20. console.log(window["value"]); // logs 10 }; inner_funct(); }; outer_funct(); I believe the reason the second log is returning undefined is because window["outer_funct"] refers to the function object, and the function object doesn't have a property "value"