[Interest] Changes to Javascript runtime in 5.12

René Hansen renehh at gmail.com
Thu Jan 3 10:29:10 CET 2019


That's what I've resorted to for now, but yeah, as you say, it's definitely
not as nice. Luckily, this time, there wasn't too many libs that needed
rewriting.

I haven't specifically seen any documentation regarding "this" and the
global scope of JS libs, so I guess it might be my own fault for relying on
that behaviour. The closest is the points about *import* semantics from
http://doc.qt.io/qt-5/qtqml-javascript-imports.html, but afaict nothing
there seems to touch on the issue I'm seeing.


/René



On Thu, 3 Jan 2019 at 10:22 Ulf Hermann <ulf.hermann at qt.io> wrote:

> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190103/81446e1f/attachment.html>


More information about the Interest mailing list