question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[question] Declare methods in scripts

See original GitHub issue

Hi, I’m not quite sure if I missed this in the docs, but is something like this possible?

[void] myMethod([int] a) {

}

myMethod(1);

running the above from new EE().ScriptEvaluate(), myMethod is defined inside of script, not on input / context, [] means optional.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
codingsebcommented, Jan 4, 2021

Also take note that variables declared in a lambda are scoped (only available) in the lambda block. But for now variables declared in other types of blocks are not scoped to their block.

var x = 1;

var myMethod = () => 
{
    var a = x + 1;
};

myMethod();

// x will be available here but not a.

But


var x = 1;

if(x == 1)
{
    var a = x+1;
}

// both x and a will be available here.

It’s in my todo list to scope variables in each blocks to behave more like in C# but in current version (1.4.18.0) it’s not done.

0reactions
lofczcommented, Feb 23, 2021

Great job, thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Writing a script containing just one function definition v.s. ...
For most cases I will declare the functions in the same script that will ... Declaring functions (or writing code) inside of a...
Read more >
Can't declare methods in a script being run in PowerShell
I'm invoking a script as described here and exemplified here. It's running and I can see the outputs to the console (both hazaa...
Read more >
function declaration - JavaScript - MDN Web Docs - Mozilla
The function declaration creates a binding of a new function to a given name. You can also define functions using the function expression....
Read more >
best way to define a function inside a script
Yes, there are now more ways to define a function. And you can now indeed put functions inside scripts. But it is almost...
Read more >
What is "right way" to call method from another script?
There is no "right way" to call a method from another object. There is only one way: <reference to the object>.methodName(); And that's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found