1

I'm using the Hash-Router library as a hash-router alongside Brython. I initially wrote the code in pure JavaScript. The definition of the route looked like this:

Router.add({
    path: '#/action/login',
    on: function() {
        /* I don't know how to port this call */
        populate_from_query(this.query);

        /* These calls can be ported: */
        Materialize.updateTextFields();
        do_login($('#email').val(), $('#password').val());
    }
});

In Brython, so far I have:

def route_on_action_login():
    # I can't write this as Python because I can't access the, "this object"
    #populate_from_query(this.query)
    
    window.Materialize.updateTextFields()
    do_login(document['email'].value, document['password'].value)

window.Router.add({
    'path': '#/action/login',
    'on': route_on_action_login
})

How can I access a function's this parameter from a Brython function passed in as a Javascript callback?

tdy
  • 36,675
  • 19
  • 86
  • 83
NeRoboto
  • 368
  • 2
  • 12

0 Answers0