Advertisement
fcamuso

Javascript Lezione 73

Aug 30th, 2022
865
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //modules_o1.html
  2. <!DOCTYPE html>
  3. <html lang="en">
  4. <head>
  5.   <meta charset="UTF-8">
  6.   <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8.   <title>Document</title>
  9. </head>
  10. <body>
  11.   <script type="module" src="./modulo.js"></script>
  12.   <script type="module" src="./modulo2.js"></script>
  13.  
  14.   <script>
  15.     alert(this);
  16.  
  17.     //import {coefficiente, metodoPubblico} from './modulo.js';    
  18.     //import * as M1 from './modulo.js';
  19.     //import coefficiente from './modulo.js';
  20.    
  21.     //import {coefficiente as coeff, metodoPubblico as metodo1, ditta, getDitta, obj, getObj} from './modulo.js';    
  22.     // alert(coeff);
  23.     // metodo1();
  24.  
  25.     //ditta = "Rockerduck inc."; NO, READ ONLY!
  26.     //getDitta();
  27.     //obj.desc = "ventola";
  28.     // alert(obj.desc);
  29.     // getObj();
  30.     //obj = {}; //NO, READ ONLY!
  31.    
  32.   </script>
  33. </body>
  34. </html>
  35.  
  36. //modulo.js
  37. //parte pubblica
  38. export const coefficiente = 1.2;
  39. //export default coefficiente;
  40.  
  41. export let ditta = "ACME spa";
  42. export let numero=300;
  43.  
  44. export function metodoPubblico() {alert('metodo pubblico invocato');}
  45. export function getDitta() {alert(ditta);}
  46. export let obj = {id: 123, desc: 'scheda video'};
  47. export function getObj() {alert(obj.desc);}
  48.  
  49.  
  50. // parte privata
  51. const privata = 35;
  52. function fprivata() {alert('io sono privata');}
  53. //alert(x);
  54.  
  55.  
  56. //modulo2.js
  57. let x = 100;
  58. //alert(this);
  59.  
  60. //occhio: aspettatevi problemi con CORS policy (vedere i video su asynchronous javascript per una completa e corretta gestione)
  61. let ris = await fetch('http://dog-api.kinduff.com/api/facts?number=5');
  62.  
  63.  
  64.  
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement