Javascript运用函数计算正方形的面积

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<script>
function Rect(w,h){
    this.width=w;
    this.height=h;
    this.area=function(){
        return this.width*this.height;
    }
}
var r= new Rect(4,8);
alert(""+r.width+""+r.height+",面积:"+r.area());
</script>
</body>
</html>

运行之后的效果如下:

posted @ 2015-06-21 11:16  roytanlu  阅读(1071)  评论(0编辑  收藏  举报