Unusual syntax in block editor documentation function()()

by WillD   Last Updated June 17, 2019 17:08 PM


The (above) example from the block editor docs has the following part when discussing how to get access to core wordpress data in the edit method of a custom block:

   edit: withSelect( function( select ) {
            return {
                posts: select( 'core' ).getEntityRecords( 'postType', 'post' )
    } )( function( props ) {

        if ( ! props.posts ) {
            return "Loading...";

        if ( props.posts.length === 0 ) {
            return "No posts";
        var className = props.className;
        var post = props.posts[ 0 ];

        return el(
            { className: className, href: post.link },
    } ),

This part has a structure like:

withSelect([anon function])([anon function])

or in other words function()()

What is going on here in JS? What is the relationship between the the two anonymous functions. Why is the second function it in parenthesis?

From running the code it is obvious that withSelect passes the return value of its anon function into the second function though its first (props) argument.

I found reference to withSelect being a higher order component, but this doesn't explain this unusual syntax, function()()

Does this syntax have a name?

Related Questions

Gutenberg RangeControl

Updated January 07, 2019 14:08 PM