admin管理员组文章数量:1401834
I am using Nodejs for writing some sample programs. I am facing an issue with calling Javascript files from within Nodejs. Say I have 3 .js files: A.js, B.js, C.js. A.js is written in Node. B.js and C.js are written in pure Javascript. Now i need to call a function b() present in B.js from A.js. So I eval() B.js and export the method b(). This works properly. But the issue is when my function b() in B.js calls a function c() in C.js.
B.js:
function b()
{
console.log('In function b');
c();
}
C.js:
function c()
{
console.log('In function c');
}
Just to add on to the question. I have a var in B.js: var abc, in the global space of B.js. In C.js I can reference to it as just: var a = abc; How to make sure my C.js can have access to my variable abc?
How do i make sure the dependancy is resolved? Any help would be appreciated. Thanks!!!
I am using Nodejs for writing some sample programs. I am facing an issue with calling Javascript files from within Nodejs. Say I have 3 .js files: A.js, B.js, C.js. A.js is written in Node. B.js and C.js are written in pure Javascript. Now i need to call a function b() present in B.js from A.js. So I eval() B.js and export the method b(). This works properly. But the issue is when my function b() in B.js calls a function c() in C.js.
B.js:
function b()
{
console.log('In function b');
c();
}
C.js:
function c()
{
console.log('In function c');
}
Just to add on to the question. I have a var in B.js: var abc, in the global space of B.js. In C.js I can reference to it as just: var a = abc; How to make sure my C.js can have access to my variable abc?
How do i make sure the dependancy is resolved? Any help would be appreciated. Thanks!!!
Share Improve this question edited Jan 22, 2013 at 9:38 user1999645 asked Jan 22, 2013 at 9:12 user1999645user1999645 1071 gold badge3 silver badges6 bronze badges 3- What's the difference between Node and "plain JavaScript"? – Bergi Commented Jan 22, 2013 at 9:20
-
What do you mean by
pure javascript
? Nodejs is pure javascript, and more. Do you mean that the functions tries to access browser'swindow
object? – Juzer Ali Commented Jan 22, 2013 at 16:03 - Since NodeJs is working in server side, It's follow some syntax to refer global variable and functions exist in different file. Please go through like nodetuts. and then change your file. I hope, there is no need to do more code changes on this, if you are done the code with more functions. Give more attention while handling prototype in your existing code. – HILARUDEEN S ALLAUDEEN Commented Jan 25, 2013 at 9:46
1 Answer
Reset to default 4You should use modules in Node.js. It very simple, just read the docs.
B.js
var c = require('./C');
function b() {
console.log('In function b');
c();
}
C.js
module.exports = function() {
console.log('In function c');
}
本文标签: Nodejs calling pure Javascript functionsStack Overflow
版权声明:本文标题:Node.js: calling pure Javascript functions - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744325068a2600686.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论