Javascript: / Home / OOP

Object Oriented Programming

The functions created so far have all become part of the "window" object. They are called Global functions because they can be called from anywhere in the Javascript.

If another script file is loaded with a global function using the same name, then the previous function is replaced with the new function. In this case it can be hard to figure out what is wrong.

When an object or other data is created in Javascript, outside of a function or another object, they also are Global and must have a unique name in the parent page.

With OOP, a Class definition can be created that contains the data values and methods required to provide custom object behavior.

When an object is created from that Class the data and method names inside the object do not have to be unique from other objects. This is called encapsulation; because the data and methods are contained and protected in the object.

An object is create from a Class by using the "new" keyword.
let myObject = new MyClass();

<- DOMValues            TitleClass ->
12Classes