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 ());
}