1

In javascript, I know I can get a value from my model into a javascript variable as follows:

function myFunctionName() 
{
    var id = @Model.ID;
    //etc
}   

What I'd like to do is customise the name of the function itself using the Model ID value, so that it comes out like:

function myFunctionName_1() 
{       
   //etc
}   

Is this possible?

2 Answers 2

3

Yes it is, if I understand you correctly. You can do it like this:

function myFunctionName_@(Model.ID)() 
{       
   //etc
}   
Sign up to request clarification or add additional context in comments.

Comments

1

You cannot change the name of the function at runtime but you can create an alias function (using your model data) and use that instead.

FYI, the arguments.callee may also be of interest to you which is basically another way to refer to function itself.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.