> - declaring a class inside a function allows me put related code together
> - can be used to simulate a closure function.
> 
> example for java:
> 
>     button.setOnClickListener(new View.OnClickListener() {
>         @Override
>         public void onClick(View v) {
>             AsyncTaskRunner runner = new AsyncTaskRunner();
>             String sleepTime = time.getText().toString();
>             runner.execute(sleepTime);
>         }
>     });

This doesn't declare a class.  This could be done by passing a lambda or
closure.

> and python:
> 
>     def subscript(event_list):
>         class MyListener(EventListener):
>             def __init__ (self, id):
>                 self.id = id
>             def on_enter (self):
>                 # do something
>                 return -1
>             def on_leave (self):
>                 # done
>         for event in event_list:
>             x = MyListener(event)
>             scheduler.add_listener(x)

This would be more illustrative if the class has "implements Listener",
and the "add_listener()" function would accept a Listener.  You then
create a class that implements Listener in a certain way.

It would work to declare the class outside of the function, but it's
nicer to keep it local to the function.  This looks like something that
can be done later.

-- 
You have heard the saying that if you put a thousand monkeys in a room with a
thousand typewriters and waited long enough, eventually you would have a room
full of dead monkeys.
                                (Scott Adams - The Dilbert principle)

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20230113141824.6CE8C1C059C%40moolenaar.net.

Raspunde prin e-mail lui