js练习构造函数和原型对象的继承方式

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript">

var shape={
type:"triangle",
getType:function(){
return this.type;
}
};
function Triangle(a,b,c)
{
this.a=a;
this.b=b;
this.c=c;
}
Triangle.prototype=shape;
Triangle.prototype.getPerimeter=function()
{
return (this.a)*(this.b)*(this.c);
};
var t=new Triangle(4,5,6);
alert(t.getPerimeter());
alert(t.getType());
</script>


</head>
<body>

</body>
</html>

posted @ 2016-10-20 11:02  天--安静  阅读(202)  评论(0编辑  收藏  举报