0

Hi I'm trying to repeat this function but each time with different arguments. This is what I have

var pathOne = function(person,place) { *script* };
pathOne(hagrid,forest);
pathTwo(barty,seawalk);

and so on...

How do I set a bunch of them equal to the function at once?

2
  • What is the significance of such assignment when the internal logic of the function is same. You should rather choose a generic name for your method to avoid such things and increase readability. This will reduce the LOC as well :) Commented Jan 26, 2015 at 7:51
  • You are right I didn't need to even add new variables Commented Jan 27, 2015 at 19:11

2 Answers 2

3

You can use the below:

var pathOne = function(person, place){ *script* },
    pathTwo = pathOne;
Sign up to request clarification or add additional context in comments.

Comments

0

To answer the question directly in your title, this is a common way to assign multiple variables to the same value:

var foo = 
    bar =
    baz = function(person, place) { /* function body */ }; 

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.