Js2Py icon indicating copy to clipboard operation
Js2Py copied to clipboard

JS function class to python

Open silverbasilisk opened this issue 3 years ago • 1 comments

Hello @PiotrDabkowski I've translated this javascript file to python and got the XX object.

** JavaScript **
XX.WSVerifyCookieReq = function () {
    this.lUid = 0;
    this.sUA = "";
    this.sCookie = "";
    this.sGuid = "";
    this.bAutoRegisterUid = 0
};

Can I declare a new WSVerifyCookieReq class which is equivalent to this?

** JavaScript **
verifyReq = new XX.WSVerifyCookieReq();
verifyReq.sUA = "new UA";

I tried like this but it's causing error.

        verifyCookieReq = XX.WSVerifyCookieReq()
        verifyCookieReq.sUA = "new UA"

silverbasilisk avatar Aug 25 '22 07:08 silverbasilisk

Sorry, I didn't understand at first. I think you can implement it like this in python:

import js2py

context = js2py.EvalJs()  
context.execute('''
var XX = [];
XX.WSVerifyCookieReq = function () {
    this.lUid = 0;
    this.sUA = "";
    this.sCookie = "";
    this.sGuid = "";
    this.bAutoRegisterUid = 0
};
''')

verifyReq = context.XX.WSVerifyCookieReq._obj.create().to_python()
# Or verifyReq = context.eval("new XX.WSVerifyCookieReq()")
verifyReq.sUA = "new UA"

worstperson avatar Dec 13 '22 08:12 worstperson