0

How to create classes in JavaScript

Background

I must admit I used to dislike JavaScript and UI development. First, I related JavaScript to Web UI design at which I am very not good at. I do not have an artistic side when it comes to programming in general. Second, I felt JavaScript was a second-class language. As I have worked on UI/JavaScript-related projects for the last seven months, I realized the need to learn more, if not impossible to master, JavaScript.

Software Environment

  • Any modern web browser

JavaScript file

Create a Student.js file and place it under js/classes. In JavaScript, you reuse the function construct to represent classes (or new reference types). Note the use of “this” within the Student function (actually it is a constructor now). To add behavior to your class, you can write functions within it or use the prototype construct as shown below.

HTML file

Sample Output

turreta_javascript_011111

Karl San Gabriel

Karl San Gabriel

Java and Enterprise Technologies Expert