Setting "this" in a class constructor

63 Views Asked by At

Similar to how you can call __init__ on anything in python

class Class():
    def __init__(self, a):
        self["a"] = a
dic = { "a": 0 } # create dict
Class.__init__(dic, 5); # "init" the dict
print(dic) # value "a" changes

How would you call constructor on anything in javscript (ie change this, before calling the constructor) The old way was apparently to use .call

<class>.call(<new this>, <arguments>)

However this no longer, works giving an error:

Class constructor <class> cannot be invoked without 'new'

I have thought of a way to do this by creating the class normally with new then copying the key, pair values to this, but that seems incredibly slow. I'm trying to get PhysiJS to run but it's an ancient codebase, and this is one of many offending lines of code which breaks it:

THREE.Scene.call( this );
0

There are 0 best solutions below