Giter Site home page Giter Site logo

Comments (4)

NiallTracey avatar NiallTracey commented on June 18, 2024 2

Thanks for your response -- that's very helpful and far more elegant than prefixing every call with window. .

"Unless I've misunderstood something, I don't see this as an issue with this
library or it's documentation, but rather your understanding of scope and
linters.
"

Well, think of it this way. Your library is incredibly useful, as it enables coders to do things they previously were unable to do. That means many of us have never been in a position to need that level of familiarity with linters or scoping rules. Globals are deliberately avoided in many tutorials on Vue for reasons of design philosophy. I discovered this module was via a suggestion on StackOverflow, and one comment in response to it (that went unanswered) was "How to call a function from the loaded script?" so I'm not the only one who got confused.

Adding a brief note in the instructions for the aid of such people will make your library easier for people to use.

Here's my suggestion, based on what you've just told me, continuing your example of the Google Maps API, and using an example from Google's API docs:

Once imported, javascript libraries can be accessed by their usual name, eg

  this.map = new google.maps.Map(document.getElementById("map") as HTMLElement, {
    center: { lat: -34.397, lng: 150.644 },
    zoom: 8,
   });

However, if you are using a linter to check your code, this may report as an undefined variable. You will need to instruct your linter to ignore this variable or function. Instructions for ESlint here

If you are unable to resolve this in your linter, adding window. before the name of the variable or function you are attempting to access will also correct this problem, e.g.:

  this.map = new window.google.maps.Map(document.getElementById("map") as HTMLElement, {
    center: { lat: -34.397, lng: 150.644 },
    zoom: 8,
   });

So no, there's nothing wrong with your instructions, and again thanks for making this incredibly useful library available. I'm just suggesting a small usability improvement.

from vue-plugin-load-script.

NiallTracey avatar NiallTracey commented on June 18, 2024 1

And obviously the answer is that I just need to qualify the scope as window.JitsiMeetExternalAPI and everything works fine.

I think it's worth including a note in the instructions to that effect:

To access a function from the loaded script, you may need to prefix the function name with window. to access the full browser scope and ensure compatibility across devices.

from vue-plugin-load-script.

Psychokiller1888 avatar Psychokiller1888 commented on June 18, 2024 1

Well, I must say it also took me a while to understand what to do with this plugin, I event uninstalled it because it basically does nothing. Until I understood it loads the scripts in the global scope. So maybe a line or two about that fact wouldn't hurt, linter or not, scope understanding or not

from vue-plugin-load-script.

tserkov avatar tserkov commented on June 18, 2024

from vue-plugin-load-script.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.