1. 程式人生 > >用字面量創建對象桌子,有屬性:長、寬、高、面積、體積 有方法:求面積、求體積

用字面量創建對象桌子,有屬性:長、寬、高、面積、體積 有方法:求面積、求體積

屬性 func function table 方法 inf document AR return

技術分享圖片

<script>
    var table = {
        length: 60,
        width: 40,
        height: 120,
        getArea : function () {
            var area= this.length * this.width;
            var volume = this.length* this.width*this.height
            document.write("面積:"+area);
            document.write(‘<br>‘+"體積:"+volume);
            return area;
        }
    }
    table.getArea();
</script>

  

用字面量創建對象桌子,有屬性:長、寬、高、面積、體積 有方法:求面積、求體積