当我将其名称命名为字符串时,如何执行JavaScript函数?
要在名称为字符串的情况下执行JavaScript函数,可以按名称访问类方法
示例
<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>热门推荐
9 医政科祝福语简短
10 生日祝福语大全女生简短
11 表达朋友的祝福语简短
12 喜事敬酒祝福语简短精辟
13 杨奕老师祝福语简短
14 过年爱情祝福语大全简短
15 给长辈祝福语简短大全
16 祝福语写给自己的简短
17 给侄子祝福语简短精辟
18 诗词文案祝福语简短精辟