简体   繁体   English

如何使用JavaScript中来自单独文件的功能?

[英]how do I use functions from separate files in javascript?

I'm working on some server-side javascript and I have some data that I want to keep sensitive, so it's in a non-public facing directory. 我正在使用一些服务器端javascript,并且我想保持敏感度,因此它位于非公开目录中。 Let's say I put it inside a function - how do I then call that function from within another javascript file? 假设我将其放在函数中-然后如何从另一个JavaScript文件中调用该函数?

Thanks to Quentin for pointing me towards the relevant documentation. 感谢Quentin向我介绍相关文档。 The solution I ended up with is: 我最终得到的解决方案是:

sensitive.js: sensitive.js:

exports.data = "data";

app.js: app.js:

var sensitive = require('./sensitive');
var data = sensitive.data;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 html 中使用 javascript 函数? - How do I use javascript functions in html? 如何在JavaScript中使用php函数? - How do I use php functions in javascript? 如何将我的JavaScript对象分成多个文件 - How do I separate my JavaScript objects into multiple files 如何获得不同的标签来加载单独的javascript文件? - How do I get different tabs to load separate javascript files? 如何从php的会话数组中获取未知数量的元素,并将其用作JavaScript中的单独变量? - How do I take an unknown number of elements from a session array in php and use them as separate variables in JavaScript? Object JavaScript 中的面向编程:如何从其他文件调用函数? - Object Oriented Programming in JavaScript: how do I call functions from other files? JAVASCRIPT:我如何从外部访问这些 javascript 成员函数? - JAVASCRIPT: How do i access these javascript member functions from outside? 如何在Javascript模块模式中使用私有函数/变量? - How do I use private functions/variables in the Javascript module pattern? 如何在两个单独的函数中使用JavaScript变量? - How can I make use of a JavaScript variable across two separate functions? JavaScript-如何将不同文件中的函数添加到类中? - JavaScript - How can I add functions from different files to a class?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM