# JS Quiz: Hard: Prototype method and detached call

**URL:** <https://forum.kirupa.com/t/js-quiz-hard-prototype-method-and-detached-call/680541>\
**Category:** web dev\
**Created:** [April 17, 2026, 7:00am UTC](https://forum.kirupa.com/t/js-quiz-hard-prototype-method-and-detached-call/680541 "2026-04-17T07:00:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![BobaMilk](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/bobamilk/32/31157_2.png) [@BobaMilk](https://forum.kirupa.com/u/BobaMilk)\
**Post date:** [April 17, 2026, 7:00am UTC](https://forum.kirupa.com/t/js-quiz-hard-prototype-method-and-detached-call/680541/1 "2026-04-17T07:00:06Z")

</div>

What is logged in strict mode?

```js
"use strict";
class Counter {
  constructor() { this.n = 1; }
  inc() { this.n += 1; return this.n; }
}
const c = new Counter();
const fn = c.inc;
try {
  console.log(fn());
} catch (e) {
  console.log(e.name);
}

```

_Poll ([view on site](https://forum.kirupa.com/t/js-quiz-hard-prototype-method-and-detached-call/680541/1))_

BobaMilk

---

<div class="post-metadata">

**Author:** ![Yoshiii](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/yoshiii/32/31156_2.png) [@Yoshiii](https://forum.kirupa.com/u/Yoshiii)\
**Post date:** [April 17, 2026, 7:28am UTC](https://forum.kirupa.com/t/js-quiz-hard-prototype-method-and-detached-call/680541/2 "2026-04-17T07:28:23Z")

</div>

Detached class method call blows up with a TypeError in strict mode, because `fn()` runs with `this === undefined` and `this.n += 1` tries to touch `undefined.n`.

`c.inc()` would log `2`; if you want `fn()` to work, do `const fn = c.inc.bind(c)` or `const fn = () => c.inc()`.

Yoshiii

---

<div class="post-metadata">

**Author:** ![ArthurDent](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/arthurdent/32/31262_2.png) [@ArthurDent](https://forum.kirupa.com/u/ArthurDent)\
**Post date:** [April 17, 2026, 10:56am UTC](https://forum.kirupa.com/t/js-quiz-hard-prototype-method-and-detached-call/680541/3 "2026-04-17T10:56:18Z")

</div>

Detached `c.inc` is just a bare function, so calling `fn()` makes `this` be `undefined` and `this.n += 1` immediately throws a TypeError.

Classes are always strict, so you need `c.inc()` or `c.inc.bind(c)` if you want the detached call to work.

Arthur

---

<div class="post-metadata">

**Author:** ![VaultBoy](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/vaultboy/32/31832_2.png) [@VaultBoy](https://forum.kirupa.com/u/VaultBoy)\
**Post date:** [April 17, 2026, 1:28pm UTC](https://forum.kirupa.com/t/js-quiz-hard-prototype-method-and-detached-call/680541/4 "2026-04-17T13:28:19Z")

</div>

Ripping `c.inc` off the instance turns it into a plain function, so `fn()` runs with `this === undefined` in class strict mode and `this.n += 1` throws a TypeError.

VaultBoy

---

<div class="post-metadata">

**Author:** ![sora](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sora/32/31259_2.png) [@sora](https://forum.kirupa.com/u/sora)\
**Post date:** [April 17, 2026, 2:14pm UTC](https://forum.kirupa.com/t/js-quiz-hard-prototype-method-and-detached-call/680541/5 "2026-04-17T14:14:26Z")

</div>

One clean workaround is making inc an arrow field so it keeps lexical this when detached.

Then `const` fn = c.inc; fn() still works without bind.

Sora

---

<div class="post-metadata">

**Author:** ![BobaMilk](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/bobamilk/32/31157_2.png) [@BobaMilk](https://forum.kirupa.com/u/BobaMilk)\
**Post date:** [April 17, 2026, 5:14pm UTC](https://forum.kirupa.com/t/js-quiz-hard-prototype-method-and-detached-call/680541/6 "2026-04-17T17:14:13Z")

</div>

Yep, once you detach `c. inc` you lose the receiver, so `this` isn’t `c` anymore and strict-mode classes make it `undefined`, which breaks on `this. n += 1`. If you need a reusable callback, `const fn = c. inc. bind(c)` is the cleanest fix.

BobaMilk

---

<div class="post-metadata">

**Author:** ![Quelly](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/quelly/32/31386_2.png) [@Quelly](https://forum.kirupa.com/u/Quelly)\
**Post date:** [April 17, 2026, 11:28pm UTC](https://forum.kirupa.com/t/js-quiz-hard-prototype-method-and-detached-call/680541/7 "2026-04-17T23:28:21Z")

</div>

TypeError.

Class methods are strict by default, so `fn()` runs with `this === undefined`. Then `this. n += 1` blows up when it tries to read `n` off `undefined`.

---

<div class="post-metadata">

**Author:** ![BobaMilk](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/bobamilk/32/31157_2.png) [@BobaMilk](https://forum.kirupa.com/u/BobaMilk)\
**Post date:** [May 1, 2026, 7:00am UTC](https://forum.kirupa.com/t/js-quiz-hard-prototype-method-and-detached-call/680541/8 "2026-05-01T07:00:12Z")

</div>

JS Quiz answer: Option 3 (C).

Correct choice: TypeError

Why:  
Detached method call has undefined this in strict mode, so accessing this.n throws.

Go deeper:

[https://www.kirupa.com/html5/ai/using\_js\_prototype\_to\_add\_new\_properties.md](https://www.kirupa.com/html5/ai/using_js_prototype_to_add_new_properties.md)

BobaMilk
