Skip to content

Using the fetch() function of Workers service binding as a const #2055

Closed Answered by kentonv
nicougou asked this question in Q&A
Discussion options

You must be logged in to vote

To turn a method into a stand-alone function, you need to bind the method to the object you got it from, not to globalThis:

env.MY_SERVICE_BIND.fetch.bind(env.MY_SERVICE_BIND)

Note that this is generally true of all methods in JavaScript, not specific to fetch or to service bindings.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nicougou
Comment options

Answer selected by nicougou
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants