2

Is it possible to use named argument in javascript?

E.g.

void method (int a, int b);

method(a:1, b:2);

1
  • 5
    I'm assuming you mean in 'javascript". jQuery is just a library. Commented May 10, 2011 at 20:59

2 Answers 2

13

In javascript you could do this:

function method(foo) {
    // use foo.a and foo.b here    
}

and then call it like this:

method({ a: 1, b: 2 });
Sign up to request clarification or add additional context in comments.

3 Comments

Can this be applied to the method I defined in my question above?
@Nam Gi VU, yes, that's the example I provided.
Oh, I mean, with the method already defined method(int a, int b) and we can changed it - e.g. use php's .attr(...) method.
1

I believe the answer is 'no', but you can come to an approximation by using a single object with names properties/members as the argument to your functions. See here for more details.

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.