node.js에 변수가있는 메소드를 호출하는 방법 이것은 그렇게합니다.node.js에 변수가있는 메소드를 호출하는 방법
var file=require("./file");
var method=b;
file.method();
// 출력 // 오류 : 형식 오류 : file.method이
방법을 사용하는 함수가 아니다?node.js에 변수가있는 메소드를 호출하는 방법 이것은 그렇게합니다.node.js에 변수가있는 메소드를 호출하는 방법
var file=require("./file");
var method=b;
file.method();
// 출력 // 오류 : 형식 오류 : file.method이
방법을 사용하는 함수가 아니다?확인이 시도 후
//file.js
module.exports = {
index: function() {
console.log("index called");
},
index2 :function() {
console.log("index2 called");
} ,
index3 : function() {
console.log("index3 called");
}
};
다음
app.get("file/:method",function (req,res)
{
var method = req.params.name;
var file = require('./file');
file[method]();
}
메서드는 고정되어 있지 않습니다. url을 파일로 호출하기 때문에 변수가 있습니다./method –
내 대답을 편집 – Banners
왜 여러 방법으로 하나의 파일에서 작동합니까? –
app.get("file/:method",function (req,res)
{
var file("./file");
var method=req.params.name;
file.method();
이 내가 말하고 싶은 것입니다
당신이 여기서 뭘하려고 무엇을
? ./file은 require에 무엇입니까? – Tommy
파일 객체에는 b() ... – Thalaivar
이라는 파일 이름이 있어야합니다. module.exports = { index : function() {}, index2 : function {}, index3 : function() {} // url : url : 3000/file/index url : 3000/file/index2 .... 이처럼 .. –