封装

作者: 洛洛kkkkkk | 来源:发表于2017-04-20 19:33 被阅读0次
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
    </body>
    <script type="text/javascript">
        function Women (name) {
            this.name = name;
//          this.age = 28;
            var age = 28;
            this.getAge = function () {
                return age;
            }
            this.setAge = function (_age) {
                age = _age;
            }
            var height = 175;
            this.getheight = function () {
                return height;
            }
            this.setheight = function (_height) {
                if(_height>=170 || _height <=150){
                    alert("身高不合法");
                }else{
                    height=_height;
                }
            }
            this.sex = "女";
            this.satName = function () {
                alert(this.name);
            }
        }
        var lucy =new Women("lucy");
        lucy.setAge(16);
        alert(lucy.getAge());
        lucy.setheight(112);
    </script>
</html>

相关文章

网友评论

      本文标题:封装

      本文链接:https://www.haomeiwen.com/subject/uhalzttx.html