I’m just trying to get a better understanding/confirmation of function arguments
In the function seen here:
function newFunction(data, status){
would the function apply specifically to data and status variables?
I don’t quite understand how the arguments work.
Basic Scenario
When a function is defined, the
()area is used for inputs. These inputs are mapped to what data is sent in.In this scenario,
datawill be assigned the value of1, andstatuswill be assigned the value of2for the scope ofnewFunction.Missmatched inputs
However, it does not always directly map. If fewer arguments are sent, then the unassigned input variables become
undefined.In this scenario,
datawill be assigned the value of1, andstatuswill be assigned the value ofundefinedfor the scope ofnewFunction.arguments object
Inside of the scope of
newFunction, there is also access to the array like object calledarguments.In this scenario, the variable
argswill hold theargumentsobject. There you can checkargs.lengthto see that only 1 argument was sent.args[0]will give you that argument value, being1in this case.Function object
A function can be made into an object with the
newkeyword. By using thenewkeyword on a function, a Function object is made. Once the Function object is made,thismay be used to refer to the current Function object instead of the global window.In this scenario,
myNewFunctionnow holds a reference to a Function object, and can be accessed as an object through dot notation or indexing.myNewFunction["data"]andmyNewFunction.datanow both hold the value of 1.