封装

2017-04-20  本文已影响0人  洛洛kkkkkk
<!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>
上一篇 下一篇

猜你喜欢

热点阅读