Use JavaScript to write a class named student. Its attributes include name, age, and tall. His methods include getname, getage, and gettall.

Source: Internet
Author: User
A few days ago, I saw the online interview questions. I used Js for my own time. I was dumpfounded. I used js to write classes. I thought this was a very basic thing. I learned it for a few days. Now I want to write it, if not, please advise:
Question: use JavaScript to write a class named student whose attributes are name, age, and tall. His methods are getname, getage, and gettall.

// Define the function first
Function student_getname ()
{
Return this. Name;
}
Function student_getage ()
{
Return this. Age;
}
Function student_gettall ()
{
Return this. Tall;
}
// Define the constructor
Function student (n, A, T)
{
// Initialize object attributes
This. Name = N;
This. Age =;
This. Tall = T;
// Define the object Method
This. getname = student_getname;
This. getage = student_getage;
This. gettall = student_gettall;
}
Function Test ()
{
// Define the function first
VaR S = new student ("James", 25,175 );
Alert (S. getname ());
Alert (S. getage ());
Alert (S. gettall ());
}

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.