JavaScript Object-oriented code practice _JS Object-oriented

Source: Internet
Author: User
So it is necessary to give an example here for the students:
JavaScript Object-Oriented code example
<textarea id="runcode58501"><script type= "Text/javascript" >//Create a site constructor, name and URL is its parameter function site (name, url) {this.url = URL; THIS.name = name; ///Add a method for site to display the URL Site.prototype.show = function () {return this.name+ "URL is:" +this.url; }; Creates a site collection constructor, Sites is its parameter function Sites (Sites) {this.sites = Sites; ///Add a method for Sites to display the URL Sites.prototype.show = function () {var retstr = ""; for (Var i=0;i<this.sites.length;i++) {retstr+=this.sites[i].show () + ""; return retstr; }; Create a new site collection, including Dream capital, Baidu, google var mysites = new Sites ([New Site ("cloud-Habitat community", "Www.jb51.net"), new site ("Baidu", "www.baidu.com"), new Site ("Google", "www.google.com")]; Print site URL document.write (mysites.show ()); </script></textarea>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

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.