[Interest] Changes to Javascript runtime in 5.12
Ulf Hermann
ulf.hermann at qt.io
Thu Jan 3 10:22:15 CET 2019
Hi René,
> In JS libs before 5.12, I've always used a closure approach to not
> leak a bunch of private variables onto the global module object. This
> results in a layout much like so:
>
> (function(lib) {
> ... closed vars can be declared here ...
>
> lib.bar = function() {
> return "baz";
> };
> })(this);
You can still pass an empty object to your anonymous function and
extract the interesting bits of that into the JS file's global scope
afterwards. Or you can declare a number of vars outside the anonymous
function and assign functions to them from inside. Both options are
indeed a bit uglier, though.
This looks like a regression in Qt 5.12, but I will need to take a
closer look at it. Did we ever document anything about the semantics of
the "this" object in JavaScript libraries?
best regards,
Ulf
More information about the Interest
mailing list