lukeed / lukeed/polka

Method context is lost when placed inside objects

Open
#188 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
5.6k
Forks
176
PR merge metrics
No merged PRs in 30d

Description

This is a this problem.

When the polka instance is placed inside an object, it looses it's own this binding.

One of my repo's handles this by taking in the contructor and binding the used methods again, but I wanted to know
if it would be possible to add them in the source itself?

Here's the file doing it for a particular use case.
https://github.com/barelyhuman/preact-ssr-starter/blob/3cb40c7eaf4bcdf985eafdd87efd0fc68e0ce767/src/lib/polka.js

I'm not sure of how often people have this usecase considering it is a micro server, but if it makes sense I don't mind raising a PR

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the Polka instance API and the referenced src/lib/polka.js implementation in the linked preact-ssr-starter example. Reproduce the lost-this behavior when a Polka instance is stored inside an object, then determine the intended binding behavior and add regression coverage before making the change.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.