Reputation: 4671
I'm following this tutorial https://developers.google.com/sheets/api/quickstart/nodejs and I'm able to read and update my sheet.
I'd like to get the credential in order to pass more parameters to my function.
authorize(JSON.parse(content), listMajors);
How can I pass 1 more parameter to listMajor?
Or How can I get auth
to pass my own function like listMajors?
function listMajors(auth) {
Upvotes: 0
Views: 67
Reputation: 201378
In your case, in order to add one more parameter to the arguments in listMajors
, how about using call
and/or apply
?
call
:authorize(JSON.parse(content), (auth) => listMajors.call(this, auth, "additionalParameter")); // or listMajors.call(null, auth, "additionalParameter")
apply
:authorize(JSON.parse(content), (auth) => listMajors.apply(this, [auth, "additionalParameter"])); // or listMajors.apply(null, [auth, "additionalParameter"])
function listMajors(auth, parameter){}
.I add 2 other methods.
authorize(JSON.parse(content), (auth) => listMajors(auth, "additionalParameter"));
In this case, the arguments can be used like function listMajors(auth, parameter){}
.
bind
:authorize(JSON.parse(content), listMajors.bind(this, "additionalParameter")); // or listMajors.bind(null, "additionalParameter")
In this case, the arguments can be used like function listMajors(parameter, auth){}
.
Upvotes: 1