封装

<!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>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容