javaScript with的用法

來源:互聯網
上載者:User

標籤:資訊   type   html   document   工具   語句塊   fun   輸入   cti   

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<script type="text/javascript">
//vehicle:交通工具

(function(){
function vehicle(weight,topSpeed,seats){
this.weight=weight;//車身重量
this.topSpeed=topSpeed;//最高時速
this.seats=seats;//座位元
}
var car=new vehicle("1.5t","280kph",5);
var bus=new vehicle("8t","200pkh",55);


document.write("<b>car 的資訊</b>");
document.write("car的重量:"+car.weight+"<br />");
document.write("car的最高時速:"+car.topSpeed+"<br />");
document.write("car的座位元:"+car.seats+"<br />");

document.write("<br />")
document.write("<b>bus 的資訊</b>");
with(bus){

document.write("bus的重量:"+weight+"<br />");     //省略Bus
document.write("bus的最高時速:"+topSpeed+"<br />");
document.write("bus的座位元:"+seats+"<br />");
}

})();
</script>
<body>
</body>
</html>

//with(對象名){

........................

}

使用with指定一個對象名,則在with語句塊中可以省略對象名,直接操作該對象的屬性和方法,簡化代碼的輸入

javaScript with的用法

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.