Can I dynamically call an object method having the method name as a string? I would imagine it like this:
var FooClass = function() { this.smile = function() {}; } var method = "smile"; var foo = new FooClass(); // I want to run smile on the foo instance. foo.{mysterious code}(); // being executed as foo.smile();
if the name of the property is stored in a variable, use []
foo[method]();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With