This code in ES6:
var myObj = {firstname: "Stevey",
printFirstName() {
console.log(this.firstname);
}}
function printNames({printFirstName}) {
printFirstName();
}
printNames(myObj);
TypeError: Cannot read property 'firstname' of undefined. How to fix this?
Edit: This question is not a duplicate. The code in 'exact' answer marked, does not take function from deconstructed object as function param. And the other answer marked is an essay on how 'this' works. That is just a reference not the direct answer.