JavaScript with usage

Source: Internet
Author: User

<! 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.