There are several ways to define a class in Javascript. I will be listing my favorite method below (JSON Method). It’s important to note that there are no real classes in JavaScript. Everything is considered an object. So below is our class definition:
JavaScript
1 2 3 4 5 6 7 8 9 10 |
<script> var Person = { age: "25", sex: "Male", location: "New York", getASL: function () { return 'Age: ' + this.age + ', Sex: ' + this.sex + ', Location: ' + this.location; } }; </script> |
So you can start using the class like this:
JavaScript
1 2 3 4 |
<script> Person.age = "29"; alert(Person.getASL()); <script> |