Question about making effectively lambdas

16 views
Skip to first unread message

CJS Hayward

unread,
Nov 20, 2023, 12:26:11 PM11/20/23
to brython
I want a function to be called with a specific value if someone clicks on an image.

I have:

    def forward_click():
        display_view(view['neighbors']['Forward'])
    if forward_clickable:
        jQuery('#forward').click(forward_click)

Is this correct? If it is not correct or could be done better, what is a preferred Brython way of making an equivalent to:

if (forward_clickable)
    {
    jQuery('#forward').click(function()
        {
        display_view(view['neighbors']['Forward'])
        });
    }

Denis Migdal

unread,
Nov 20, 2023, 3:34:13 PM11/20/23
to bry...@googlegroups.com
At first glance it seems correct.

You can move the def forward_click inside the if if you want to.


Generally, in JS we import JQuery as $, because it's 5 less characters and we are lazy. xD
Though, nowadays, I'm not sure we use JQuery a lot since vanilla JS is now more standardized.


In pure Brython (without using the JS/DOM API), we'd do :
document['forward'].bind('click', ...)

After, do with what you are most confortable with.

--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brython/505fac3e-299d-415b-ba1d-d139b01b0fdfn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages