-2
Hello, it is not possible to do this type of include in JS.
But you can use import
and export
to reuse code within another file. However, in an Ecmascript 6 feature not yet implemented in all browsers you need to use transpilers like Babel to work
Ex.:
given the file Function.js
function returnName(name) {
console.log('Olá ' + name)
}
export default returnName
and index.js file
import returnName from './function'
returnName('Salatiel)
// Olá, Salatiel
If it’s just include, it’s okay to copy all the contents of
arquivo.js
and paste at the top of the contents ofarquivo2.js
. Now, if you need to use a function created in the first file, edit your question and better describe what you need to do.– Renan Gomes