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>

运行之后的效果如下:

原文地址:https://www.cnblogs.com/roytanlu/p/4591740.html