<! DOCTYPE html>
<meta charset= "UTF-8" >
<title></title>
<script type= "Text/javascript" >
Vehicle: Transportation
(function () {
Function Vehicle (weight,topspeed,seats) {
this.weight=weight;//body weight
this.topspeed=topspeed;//Top speed
this.seats=seats;//Number of seats
}
var car=new vehicle ("1.5t", "280kph", 5);
var bus=new vehicle ("8t", "200pkh", 55);
document.write ("<b>car information </b>");
document.write ("Car Weight:" +car.weight+ "<br/>");
document.write ("Car's top speed:" +car.topspeed+ "<br/>");
document.write ("Number of seats in car:" +car.seats+ "<br/>");
document.write ("<br/>")
document.write ("<b>bus information </b>");
With (bus) {
document.write ("Bus Weight:" +weight+ "<br/>"); Omit bus
document.write ("Bus Top speed:" +topspeed+ "<br/>");
document.write ("Number of seats on bus:" +seats+ "<br/>");
}
})();
</script>
<body>
</body>
With (object name) {
........................
}
Using with to specify an object name, you can omit the object name from the With statement block, manipulate the object's properties and methods directly, and simplify the input of the Code
JavaScript with usage