Object Oriented Programming in JavaScript

Object Oriented Programming
Object-oriented programming is a paradigm in programming that classifies functions, procedures, variables or related constants in a single unit (class) like objects in the real world. The object itself is a form of class, generally known as instant. The techniques in this programming are the development of previous techniques such as modularity, polymorphism, and encapsulation. Currently there are many programming languages that support this object-oriented programming, such as C ++, C #, Java, Javascript, PHP, Python, Ruby, and Objective C.
In PBO each program will declare a collection of objects and not a collection of functions or a collection of lines of code. In this PBO each object has the ability to receive messages, process data and send data to other objects. Each object can be seen as its own program which has its own roles and responsibilities. Program development using PBO techniques is popular in large-scale programs because it is flexible and makes it easy to improve.

Prototype Based Programming
Javascript uses PBO with prototype-based programming models. This model does not recognize classes, there are objects. Objects in this model can be modified runtime such as adding variables (properties) or methods (functions / procedures). This model is also known as the classless PBO programming, prototype oriented or instant based. Javascript Object Oriented Programming

Main Object (Default)
Javascript has many default objects such as Math, Arrays, Strings and Objects. Each object in Javascript is an instance of an Object object, so it has all the properties and methods available.
Artificial Object
Javascript is a PBO language that uses the keyword function to define a class. Therefore, class creation is the same as creating functions in Javascript. The following is a format that can be used to define classes in javascript.

Or in a more complete form
The thing that can be considered in the above format is namavar1 and namavar2 is the property of that class. Making the property of an object is done by adding this keyword at the beginning of the property name, as shown in the format above. While making methods or functions of objects is done in the same way only with properties by adding the definition of the function using the keyword function.
Making the object of the class defined above can be done using the following format.
Then to access the property or method that is owned by an object can use the point operator (.) After the object name is followed by the name of the property or method. Regarding class naming rules can follow the function naming rules in the previous material
Examples of implementation, Make a web page as follows
Save the file as square pbo.html
Example of calculating square area and circumference using a prototype, Make a web page as follows
Save the file with the name proto pbo.html
Another example
Save the file as closure pbo.html
Another example makes a word with a prototype
Save the file with the name kata_proto_pbo.html

0 Response to "Object Oriented Programming in JavaScript"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel