0

This is a JavaScript question.

In ColdFusion, we use arguments.CustID when referring to CustID that was passed to a function.

Q: Is there any way in JavaScript to refer to the scope of a parameter so that 6 months from now I know that "This variable is in the arguments scope"?

I'm considering adding arg to the beginning of my variable names, so that I would have argCustID.

Phillip Senn
  • 46,771
  • 90
  • 257
  • 373
  • Did you see this? http://stackoverflow.com/questions/500431/javascript-variable-scope – Miguel-F Apr 03 '13 at 15:58
  • 4
    you could start passing your arguments as an object. args = { arg1: hello, arg2: world }. then inside your functions you would use args.arg1 just like your coldfusion example. – Decker W Brower Apr 03 '13 at 15:59
  • Thanks Decker. That's a good idea. I do something similar in ColdFusion where I pass the form scope sometimes. – Phillip Senn Apr 03 '13 at 16:02
  • @Miguel-F, hmmm... There's a lot to read and comprehend with that link. Was there something in particular you wanted me to see? – Phillip Senn Apr 03 '13 at 16:04
  • Here is a similar question: http://stackoverflow.com/questions/11796093/named-parameters-in-javascript – David Hellsing Apr 03 '13 at 16:05
  • Kinda. I think he's asking from the calling perspective: How can I name parameters. – Phillip Senn Apr 03 '13 at 16:08
  • I just thought the highest rated answer on that page showed some good examples of the different scopes in javascript. I realize it doesn't really answer your question but I thought it might give you better insight to how the scopes behave. @DeckerWBrower might have the best suggestion for you. – Miguel-F Apr 03 '13 at 16:09
  • Arguments in js functions can also be accessed by their numerical indexes, e.g. `arguments[0]`. But I believe what you want is to pass an object, as Brower suggested. – bfavaretto Apr 03 '13 at 16:13

0 Answers0