javascriptjavascript-namespaces

How to import or use functions defined in third party namespace in javascript?


This could be the very basic question of javascript but i am not able to figure out to use the namespance named AudioBridge from the kandy.js file but i dont how should i import the audioBridge namesame in my own js and use it.

Here is the CDN link of kandy.js

Following is the screenshot of the kandy apis AudioBridge feature , how shall i able to use these apis defined in the kandy.js

enter image description here

Link to kandy documentation


Solution

  • In your html you will have you script tag like this:

        <script src="myJavascriptFile.js" type="module"></script>
    

    The type is required and will allow you to use imports in your script.

    Your Javascript file will then look like this:

        import { create } from '/whereEverIStore/kandy.js';
    
        const client = create({
          authentication: { ... },
          logs: { ... },
          // .... more
        });    
    

    I hope this helps.

    NOTE: the { create } syntax is destructuring and can be found here: MDN Destructuring