Javascript dependency

2

I am using Framework7 to make a mobile application with phonegap . My doubt arises with javascript , in which I am totally new. My question is if I can import a .js from another .js for example;

  

A main document main.js

  main.js
    metodo(){
    //hace algo
    }  
  

Another docuemento, uso.js, that uses main.js

 utilidad.js 
    importo main.js
    //llamo a método de main.js
    metodo()
    
asked by JoCuTo 02.05.2017 в 11:33
source

1 answer

1

In this answer from SO in English, you have many ways.

I find this interesting, since you only import a specific method instead of the entire file:

// main.js
export function metodo() {
  return "Hello";
}

// utilidad.js
import {metodo} from 'main.js'; // o './main.js'
let val = metodo(); // val es "Hello";

or if you want the whole file, with

answered by 02.05.2017 / 11:38
source