Coder Social home page Coder Social logo

Comments (6)

codingseb avatar codingseb commented on September 23, 2024 1

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.

from expressionevaluator.

codingseb avatar codingseb commented on September 23, 2024

It's not directly possible with the standard syntax of a method for now. But it's possible to declare some multiline lambda like function. I know it's not well documented.
But you can write something like :

var myMethod = (a) => 
{
    //Do something with a
};

myMethod(1);

I will add some docs about this.

from expressionevaluator.

lofcz avatar lofcz commented on September 23, 2024

Thanks for the reply, multiline lambda will do for now. For the sake of backwards compatibility it would be nice to have another setting to toggle this.

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.

If possible it would be fine to leave this open for now, for other newcomers around, I guess this would be a frequent question.

from expressionevaluator.

codingseb avatar codingseb commented on September 23, 2024

it would be nice to have another setting to toggle this.

Yes good idea. I will add an option for this.

If possible it would be fine to leave this open for now, for other newcomers around, I guess this would be a frequent question.

Yes I leave this open.

from expressionevaluator.

codingseb avatar codingseb commented on September 23, 2024

I added a small documentation about using lambda for method simulation here

I always keep this issue open

from expressionevaluator.

lofcz avatar lofcz commented on September 23, 2024

Great job, thanks!

from expressionevaluator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.