Date: 2009jul22
Keywords: OOP, OO
Language: javaScript
Q. Can you explain Object-Oriented javaScript?
A. There are other tutorials on the web but I find most of them too verbose.
Here's the short answer. UPPER_CASE names are selected by you.
function CLASS() {
var PRIVATE_VARIABLE; // This variable can NOT be accessed from outside the class
var PRIVATE_MEMBER_FUNCTION = function(param1, param2) { // This member function can NOT be accessed from outside the class
// Do stuff
}; // <--- Note the semi-colon!
var CONSTRUCTOR = function() {
// Do stuff
}; // <--- Note the semi-colon!
this.PUBLIC_VARIABLE; // This variable CAN be accessed from outside the class
this.PUBLIC_MEMBER_FUNCTION = function(param1, param2) { // This member function can be accessed from outside the class
// Do stuff
}; // <--- Note the semi-colon!
CONSTRUCTOR(); // Call the private member function called CONSTRUCTOR to initialize
}; // <--- Note the semi-colon!
// That's it.
// Example use:
var a = new CLASS;
a.PUBLIC_VARIABLE = 25;
a.PUBLIC_MEMBER_FUNCTION(1,2);
| What this info useful to you? You can donate to say thanks |
Add a comment
Sign in to add a comment