What is the syntax for Function.prototype.call or Function.prototype.apply with an async function
up vote
-1
down vote
favorite
What is the syntax for using the call()
or apply()
methods to change this
when dealing async
functions?
So by way of example:
class Foo {
async someLongMethod(){
... Do stuff
}
}
class Bar {
async someOtherMethodThatWillWait(){
//Will the following work?
await Foo.prototype.someLongMethod.call(this);
}
}
javascript async-await
|
show 2 more comments
up vote
-1
down vote
favorite
What is the syntax for using the call()
or apply()
methods to change this
when dealing async
functions?
So by way of example:
class Foo {
async someLongMethod(){
... Do stuff
}
}
class Bar {
async someOtherMethodThatWillWait(){
//Will the following work?
await Foo.prototype.someLongMethod.call(this);
}
}
javascript async-await
2
Will the following work
Why not just try it? It looks OK to me
– CertainPerformance
Nov 22 at 8:15
1
await
acts on promises, so as that method returns a promise you're fine. It's certainly syntactically valid.
– jonrsharpe
Nov 22 at 8:16
@jonrsharpe Since it's anasync
function, it will necessarily return aPromise
– CertainPerformance
Nov 22 at 8:16
@CertainPerformance ah, hadn't spotted that it was also in the example, thanks!
– jonrsharpe
Nov 22 at 8:17
1
No, Promises in any form are not synchronous (except when calling the constructor, initially)
– CertainPerformance
Nov 22 at 8:33
|
show 2 more comments
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
What is the syntax for using the call()
or apply()
methods to change this
when dealing async
functions?
So by way of example:
class Foo {
async someLongMethod(){
... Do stuff
}
}
class Bar {
async someOtherMethodThatWillWait(){
//Will the following work?
await Foo.prototype.someLongMethod.call(this);
}
}
javascript async-await
What is the syntax for using the call()
or apply()
methods to change this
when dealing async
functions?
So by way of example:
class Foo {
async someLongMethod(){
... Do stuff
}
}
class Bar {
async someOtherMethodThatWillWait(){
//Will the following work?
await Foo.prototype.someLongMethod.call(this);
}
}
javascript async-await
javascript async-await
asked Nov 22 at 8:14
Tom Maher
6771126
6771126
2
Will the following work
Why not just try it? It looks OK to me
– CertainPerformance
Nov 22 at 8:15
1
await
acts on promises, so as that method returns a promise you're fine. It's certainly syntactically valid.
– jonrsharpe
Nov 22 at 8:16
@jonrsharpe Since it's anasync
function, it will necessarily return aPromise
– CertainPerformance
Nov 22 at 8:16
@CertainPerformance ah, hadn't spotted that it was also in the example, thanks!
– jonrsharpe
Nov 22 at 8:17
1
No, Promises in any form are not synchronous (except when calling the constructor, initially)
– CertainPerformance
Nov 22 at 8:33
|
show 2 more comments
2
Will the following work
Why not just try it? It looks OK to me
– CertainPerformance
Nov 22 at 8:15
1
await
acts on promises, so as that method returns a promise you're fine. It's certainly syntactically valid.
– jonrsharpe
Nov 22 at 8:16
@jonrsharpe Since it's anasync
function, it will necessarily return aPromise
– CertainPerformance
Nov 22 at 8:16
@CertainPerformance ah, hadn't spotted that it was also in the example, thanks!
– jonrsharpe
Nov 22 at 8:17
1
No, Promises in any form are not synchronous (except when calling the constructor, initially)
– CertainPerformance
Nov 22 at 8:33
2
2
Will the following work
Why not just try it? It looks OK to me– CertainPerformance
Nov 22 at 8:15
Will the following work
Why not just try it? It looks OK to me– CertainPerformance
Nov 22 at 8:15
1
1
await
acts on promises, so as that method returns a promise you're fine. It's certainly syntactically valid.– jonrsharpe
Nov 22 at 8:16
await
acts on promises, so as that method returns a promise you're fine. It's certainly syntactically valid.– jonrsharpe
Nov 22 at 8:16
@jonrsharpe Since it's an
async
function, it will necessarily return a Promise
– CertainPerformance
Nov 22 at 8:16
@jonrsharpe Since it's an
async
function, it will necessarily return a Promise
– CertainPerformance
Nov 22 at 8:16
@CertainPerformance ah, hadn't spotted that it was also in the example, thanks!
– jonrsharpe
Nov 22 at 8:17
@CertainPerformance ah, hadn't spotted that it was also in the example, thanks!
– jonrsharpe
Nov 22 at 8:17
1
1
No, Promises in any form are not synchronous (except when calling the constructor, initially)
– CertainPerformance
Nov 22 at 8:33
No, Promises in any form are not synchronous (except when calling the constructor, initially)
– CertainPerformance
Nov 22 at 8:33
|
show 2 more comments
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
It's exactly the same as the syntax for calling normal functions, there is no difference. You cannot really distinguish an async function
from any other function
that returns a promise.
I managed to test the call within protractor through node using a browser wait and it does indeed work. Thanks for everyone's input.
– Tom Maher
Nov 22 at 10:09
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
It's exactly the same as the syntax for calling normal functions, there is no difference. You cannot really distinguish an async function
from any other function
that returns a promise.
I managed to test the call within protractor through node using a browser wait and it does indeed work. Thanks for everyone's input.
– Tom Maher
Nov 22 at 10:09
add a comment |
up vote
2
down vote
accepted
It's exactly the same as the syntax for calling normal functions, there is no difference. You cannot really distinguish an async function
from any other function
that returns a promise.
I managed to test the call within protractor through node using a browser wait and it does indeed work. Thanks for everyone's input.
– Tom Maher
Nov 22 at 10:09
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
It's exactly the same as the syntax for calling normal functions, there is no difference. You cannot really distinguish an async function
from any other function
that returns a promise.
It's exactly the same as the syntax for calling normal functions, there is no difference. You cannot really distinguish an async function
from any other function
that returns a promise.
answered Nov 22 at 9:07
Bergi
359k55533850
359k55533850
I managed to test the call within protractor through node using a browser wait and it does indeed work. Thanks for everyone's input.
– Tom Maher
Nov 22 at 10:09
add a comment |
I managed to test the call within protractor through node using a browser wait and it does indeed work. Thanks for everyone's input.
– Tom Maher
Nov 22 at 10:09
I managed to test the call within protractor through node using a browser wait and it does indeed work. Thanks for everyone's input.
– Tom Maher
Nov 22 at 10:09
I managed to test the call within protractor through node using a browser wait and it does indeed work. Thanks for everyone's input.
– Tom Maher
Nov 22 at 10:09
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53426463%2fwhat-is-the-syntax-for-function-prototype-call-or-function-prototype-apply-with%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Will the following work
Why not just try it? It looks OK to me– CertainPerformance
Nov 22 at 8:15
1
await
acts on promises, so as that method returns a promise you're fine. It's certainly syntactically valid.– jonrsharpe
Nov 22 at 8:16
@jonrsharpe Since it's an
async
function, it will necessarily return aPromise
– CertainPerformance
Nov 22 at 8:16
@CertainPerformance ah, hadn't spotted that it was also in the example, thanks!
– jonrsharpe
Nov 22 at 8:17
1
No, Promises in any form are not synchronous (except when calling the constructor, initially)
– CertainPerformance
Nov 22 at 8:33