I'm working in a brunch project.
I have two javascript files, let's say A.js and B.js
A.js:
function replacer(key, value) {
if (typeof value === 'number' && !isFinite(value)) {
return String(value);
}
return value;
};
B.js:
atts = ...
json = JSON.stringify(atts, replacer);
In my html I do:
<script type="text/javascript">
require('scripts/front/A');
require('scripts/front/B');
</script>`
When javascript B is executed I got replacer is not defined.
It is possible to call functions from different files?
In a.js
module.exports = function (key, value) {
if (typeof value === 'number' && !isFinite(value)) {
return String(value);
}
return value;
};
In b.js: var replacer = require('path/to/a.js');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.