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 <[email protected]> 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 > >
_______________________________________________ Interest mailing list [email protected] https://lists.qt-project.org/listinfo/interest
