0

In Javascript is there a variable representing the context of a function, in which the arguments are named attributes (not array indexes)?

Apologies for not including research results, I'm trying to find the words to search for.

function f (a,b,c) {
   console.log(a); // this returns `4`, but is there an object `a` is an attribute of?
   console.log(arguments[0]); // this returns `4` but I'm looking for ?.a not ?[0]
   console.log(this.a) // returns `undefined` and is not the idea I seek
   console.log(window.a) // returns `undefined` and is not the idea I seek
   console.log(context.a) // is there a variable for the **context** of this function?
}

f(4,9, 13)
Not A Bot
  • 2,474
  • 2
  • 16
  • 33
prototype
  • 7,249
  • 15
  • 60
  • 94
  • 1
    Is there a reason you don't just pass an object to `f` as its sole parameter? Then you could access a, b, and c as attributes of the object you pass. Is there a specific reason you need to get arguments as attributes of some object? – kingkupps Dec 29 '20 at 04:29
  • @kingkupps Great question. My goal was to call a function with named params e.g. `f(4, 9 13)` for conciseness and pass the arguments as an object like you suggest `{a: 4, b: 9, c: 13)` to another function, and just assumed this would be a trivial thing in JS – prototype Dec 29 '20 at 04:52

0 Answers0