码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript 动态选择方法和属性

时间:2015-01-02 22:20:48      阅读:311      评论:0      收藏:0      [点我收藏+]

标签:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
    alert(‘aa‘);
    function ClassA(){
        this.PropertyA = "PropertyA";
        this.MethondA = function(p1,p2){
            alert("MethondA");
            alert(p1);
            alert(p2);
        };
        this.MethondB = function(p1,p2){
            alert("MethondB");
            alert(p1);
            alert(p2);
        };
        this.SelectMethond= function(){
            return true;
        };
    }
    var obj = new ClassA();
    // 属性A
    alert(obj.PropertyA);
    // 使用方括号操作符
    alert(obj["PropertyA"]);
    // 使用方括号操作符方法
    obj[obj["SelectMethond"]()?"MethondA":"MethondB"](obj["PropertyA"],"p2");
    </script>
</head>
<body>

</body>
</html>

JavaScript 动态选择方法和属性

标签:

原文地址:http://www.cnblogs.com/tangruixin/p/4198871.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!