0

클라이언트 측의 요청에 따라 서버 측 변수가 달라 지므로 사용할 함수를 결정합니다. 이 함수는 다른 함수 호출을 시작한다는 점을 제외하고는 서로 비슷하게 보입니다. 따라서 함수 이름을 변수로 바꿀 수 있다면 생각 중입니다. 내가 생각하고 무엇을coffeescript가있는 서버 측의 변수에 그 이름의 일부가있는 함수를 호출하십시오.

예 :

sortFunction = req.body.sortValue

path.sortFunction의 ARG1, ARG2 (콜백) -> 다른 잘못을 ... 경우. ..

답변

2

당신은 항상 자신의 이름으로 자바 스크립트/커피 스크립트 Object의 속성에 액세스 할 수 있습니다

# suppose you have an object, that contains your sort functions 
sortFunctions = 
    quickSort: (a, b, cb) -> ... 
    bubbleSort: (a, b, cb) -> ... 
    insertionSort: (a, b, cb) -> ... 

# you can access those properties of sortFunction 
# by using the [] notation 

sortFunctionName = req.body.sortValue 
sortFunction = sortFunctions[sortFunctionName] 

# this might return no value, when 'sortFunctionName' is not present in your object 
# you can compensate that by using a default value 
sortFunction ?= sortFunctions.quickSort 

# now use that function as you would usually do 
sortFunction arg1, arg2, (err, data) -> if err ... else ... 

도움이 되길 바랍니다.)

+0

감사합니다. I는 "(A, B, CB)를 ->"왼쪽 비록 일부 멀리있는 동안 항상 동일한 인수 .. 기본적 SortFunctions = 퀵 : path.variableName 및 sortFunction ARG1, ARG2 (콜백) - > .... .... – user1969202

관련 문제