There are n number of OOPS functionality available in Javascript. Some of the basic OOPS terminologies are namespaces, classes, object, constructor, method and much more. Now I will explain one by one with syntax and definition of these terms.
Namespaces: Namespace is a container which provides developer bunch of functionality in a unique application with a specific name.
var MYAPP = MYAPP || {};
The basic terminology definition of Object-Oriented JavaScript are :
Classes: It is used to define object characteristics.
Property:An object characteristic, such as color.
Method:An object capability.
Constructor: It has the same name as the class containing it. A constructor is called when the instance of an object is created.
Object: An instance of a class is called object.
Now By giving an example I will explain all the points.
var MYAPP = MYAPP || {};
MYAPP.event = {};
MYAPP.commonMethod = {
regExForName: "",
regExForPhone: "",
validateName: function(name){
},
validatePhoneNo: function(phoneNo){
}
}
MYAPP.event = {
addListener: function(el, type, fn) {
},
removeListener: function(el, type, fn) {
},
getEvent: function(e) {
}
}
MYAPP.event.addListener("yourel", "type", callback);
Here In the above example, we can see we have created the namespace MYAPP then we have created a container called MYAPP.commonmethod for common method and property. Then we have define variable for checking validation and then define a function to use all the method.
0 Comment(s)