const info = {
name: 'Steve',
phone: 20655564,
email: '[email protected]',
sayName: function(){
console.log('Hello I am ' + info.name);
},
};
I made a random object and was using a different function to call that objects method.
function invokeMethod(object, method) {
// method is a string that contains the name of a method on the object
// invoke this method
// nothing needs to be returned
const func = object[method]
object.func();
}
invokeMethod(info, 'sayName');
However, when I when I run the invokeMethod function above I get the error func is not a function. However, when I run
return func
as a test I get
[function]
trying to figure out how to get it to do the sayName method
object[method]();orfunc.call(object);