JavaScript Object-oriented function class _js object-oriented

Source: Internet
Author: User
As follows:
Copy Code code as follows:

function Student ()
{
Defines a field in the class student and assigns an initial value, but the access rights for this field are public
This.studentno = ' s001 ';
This.studentname = ' xiaoming ';
This.sex = ' Male ';
Defines the method Updatestudentname in the class student to modify the Studentname value
This.updatestudentname = function (studentname)
{
This.studentname = Studentname;
}
}

A student class is defined as the code above, and contains Studentno, Studentname,
Sex 3 fields, method Updatestudentname.
The following will be invoked with the following code:
Copy Code code as follows:

var s = new Student (); To create an object of the student class
Alert (' School No.: ' +s.studentno);
Alert (' Name: ' +s.studentname);
Alert (' Sex: ' +s.sex);

Before the Updatestudentname method is invoked, the number, name, and gender values are shown:
School Number: s001
Name: Xiao Ming
Sex: Male

Then call Updatestudentname to modify the value of the Studentname, the code is as follows:
Copy Code code as follows:

S.updatestudentname (' Xiao Qiang ');
Alert (' School No.: ' +s.studentno);
Alert (' Name: ' +s.studentname);
Alert (' Sex: ' +s.sex);

Again, the study number and gender will not change, the results are as follows:
School Number: s001
Name: Xiao Qiang
Sex: Male

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.