Skip to content

Any experience with Typescript/ES6 class Strategies? #886

Answered by rbeer
rbeer asked this question in Help
Discussion options

You must be logged in to vote

Alright, got it; and it was just me not seeing the wood for the trees.

Two things:

  1. Arrow functions bad
    Arrow functions don't have a reference on this - ever.

Don't do this

verified: VerifiedCallback = (err, user, info) => {}

Do that

verified(err, user, info) {}
  1. Bind the verified callback to the class
this.verify(req, user, this.verified.bind(this));

Otherwise the this reference inside the callback will be undefined - or worse something entirely else.

The wild days of ES5. I guess Crockford was right, after all. 😄

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by rbeer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
1 participant