Question #30445

how to create a class named Student?
1

Expert's answer

2013-05-15T11:22:11-0400

- Problem

How to create a class name Student?

- Solution

Javascript is a special language which don't have its own realization of classes. Honestly, they are not needed there, but if you want them, there are lots of "crutches" which can help you – choose one to your taste. They are different, so if you need you can look about libraries JS.Class, jsOOP, framework MooTools, etc. I will show you an alternative, which is really practical in javascript – objects. Thus this code (in pseudocode):


class Student { // Declaration of the class
public any_value = "test"; // Public variable
public Pair() { // Public method
return "The variable \"any_value\" contains value ""+this -> any_value+"""; }
}


Is an equivalent of this code in javascript:


Student = { // Declaration of the object
any_value : "test", // Public variable
Pair : function() { // Public method
return "The variable \"any_value\" contains value ""+this.any_value+"""; }
}
alert(Student.Pair()); // Alerts "The variable "any_value" contains value "test"

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS