<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
//方法一
function cube(length,width,height){
var obj={}
obj.length=length
obj.width=width
obj.height=height
obj.__proto__=cube.prototype
return obj
}
// 周长公式
cube.prototype.zc=function(){
return (this.width+this.length+this.height)*4
}
// 体积公式
cube.prototype.volume=function(){
return this.length*this.width*this.height
}
var c1=cube(10,20,30)
console.log(c1);
console.log(c1.zc());
console.log(c1.volume());
//方法二
function go(length,width,height){
this.length=length
this.width=width
this.height=height
}
// 周长公式
go.prototype.zc=function(){
return (this.width+this.length+this.height)*4
}
// 体积公式
go.prototype.volume=function(){
return this.length*this.width*this.height
}
var c1=new go(10,20,30)
console.log(c1);
console.log(c1.zc());
console.log(c1.volume());
</script>
</body>
</html>