Last active
March 28, 2020 02:17
-
-
Save kena0ki/fc51bb45a509687d2afdbcdc028c9e9a to your computer and use it in GitHub Desktop.
I expected fnc prints MyClass, at least the last one, but actually it printed undefined.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
function MyClass() { | |
function fnc() { | |
console.log(this, 'in fnc'); | |
} | |
const arrow = () => { | |
console.log(this, 'in arrow'); | |
} | |
const bind = function() { | |
console.log(this, 'in bind'); | |
}.bind(this) | |
this.method = () => { | |
fnc(); // undefined | |
arrow(); // MyClass | |
bind(); // MyClass | |
console.log(this, ' in method.'); // MyClass | |
} | |
fnc(); // undefined | |
} | |
const obj = new MyClass(); | |
obj.method(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment