Giter Club home page Giter Club logo

proposal-immediately-executable-arrow-functions-expression's Introduction

Introduction

Hello,

I had an idea to allow returns from statements and decided to do a research and found Do Expression proposal very similar and more complex than my idea.

My idea is basically to create a new keyword syntax as a shortcut for an executed arrow function. It behaves same as arrow function.

Examples:

const 
 a=1,
 b = do if(a) return 1; else return 0;;

Transpilation:

const 
 a=1,
 b = (()=> {if(a) return 1; else return 2})();

We can also use alternative names or keywords for this new feature.

Examples:

  • ->
  • => (preceded by an expression and followed by a block or a statement)
const 
 a=1,
 b = -> if(a) return 1; else return 0;;
const 
 a=1,
 b = => if(a) return 1; else return 0;;

Or

const 
 a=1,
 b = =>{ if(a) return 1; else return 0;};

We might call => syntax a Immediately Executed Arrow Function

We can even pass parameters as an object:

const 
 a=1,
 b = {value:a} => if(value) return value; else return 0;

Match Example:

const a=1,b=2;
const c = 
    {a,b}=> {
        if(a) return a; 
        else if(b) return b; 
        else return 0;
    }
console.log(c)

Pipe and Chaining Example

Consecutive chains inherit the single parameter of single field object of parent chain, each assigning return value to that single field object property and passing that as parameters to next chain. We can enforce rule for my proposal to only have one object with one field as the parameter, that field can be be assigned as any object of course.

const value=1;
const c = {value} 
    => value+1
    => value+1
    => value+2
console.log(c) //5

Alternative Syntax:

const c = value
    -> value+1
    -> value+1
    -> value+2
console.log(c) //5

We can use for chaining ==> syntax to avoid specifying the parameter with the method: {value} ==> Filter ==> Map = {value} => Filter(value) => Map(value)

We can of course discuss the syntax, my proposal has 3 suggestions: =>, ->, do. The reason I prefer => is because my method is actually based on anonymous method, just immediately executed, and allowing flexibility.

Thank you,

proposal-immediately-executable-arrow-functions-expression's People

Contributors

edsaleh avatar

Watchers

 avatar  avatar

proposal-immediately-executable-arrow-functions-expression's Issues

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.