This question has already been answered:

'use strict' class A { constructor(){} Do(){ alert(this) } } let a = new A() a.Do() let b = a.Do b() 

Why does the second call display undefined?

Reported as a duplicate at Grundy. javascript 18 Jul '17 at 10:13 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    1 answer 1

    Because it uses "use strict"

    When using "use strict" - this is the default - undefined

    In the first call this - points to the object.

    But after receiving the reference to the function and performing

     let b = a.Do; b(); 

    The context is changed to a global object, or, when using "use strict" to undefined

    Also in mdn

    Body class definitions, and class expressions are run in strict mode.

    • I do not understand. Well, yes, the function is not called on behalf of the object, but because it is its prototype. Sorry, but I'm new to javascript, and this behavior seems very strange to me. - Alster
    • @Alster, reconcile :-) the value of this depends on how exactly the function was called - Grundy