Để thực thi một hàm JavaScript khi tên của nó là một chuỗi, bạn có thể truy cập các phương thức lớp theo tên
Ví dụ
Bản trình diễn trực tiếp
<html>
<body>
<script>
class Demo {
methodOne(){
document.write("50");
}
methodTwo(){
this['methodOne']();
document.write("<br> 100");
}
}
let num = new Demo();
num['methodTwo']();
</script>
</body>
</html>