- 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"
Comments