SlideShare a Scribd company logo
Vitali Hornik, PMPÂź
Ph.D. in IT (Computer Science)
Do you know everything about
JavaScript OOP?
The main code of procedural programming is constantly
processing various situations.
The main code of OOP tries to pass responsibility to the
executor - system objects.
Procedural Programming vs OOP
0
5
10
15
20
25
30
Month1
Month3
Month5
Month7
Month9
Month11
Month13
Month15
Month17
Month19
Month21
Month23
Month25
Pct.
OOP
Your efforts and worries at the project
Job satisfaction is inversely proportional to them

and a new project task will make you totally happy!
Like this

3 major principles of OOP
1. Encapsulation by means of closures
2. Inheritance via prototyping
3. Polymorphism - JS is not a typed language 
1. interfaces and abstract classes*
2. final classes
3. protected modifiers
4. static class members
JS doesn’t have
this
var obj = { outerWidth : 20 };
function getWidth() { return this.outerWidth; }
var a = getWidth ();
var b = getWidth.apply(obj);
this points to the object in the context of which the code works
Can this be changed?
1. var obj = new SomeFunction(
); // the created object
2. obj.publicFunction(
.); // obj
3. someFunction.apply(obj,[arg1,arg2,
.]); // obj
4. someFunction.call(obj, arg1,arg2,
.); // obj
4front en
prototype and/or __proto__
function A() {
.}
A.prototype – an object with one property «constructor».
A.prototype.constructor – function А
A.__proto__ – Function.prototype, the child of Object.
Object is the parent of everything.
alert(A.__proto__ === A.prototype.constructor.__proto__ ); // true
A
Function
Object
prototype
__proto__
prototype
__proto__
prototype
prototype – specifies the properties of created objects
__proto__ – everything has __proto__ , it serves for parent/child
connection
function A(args) {
.}
var obj = new A(args);
1. var obj = {};
2. obj.__proto__ = A.prototype;
3. var newConstructor = A.apply(obj, [args]);
4. obj = newConstructor instanceof Object ? newConstructor : obj;
alert(obj.prototype); // undefined
alert(obj.__proto__ === A.prototype); // true
alert(obj.__proto__.__proto__ === Object.prototype); // true
new
var obj = new A();
A.__proto__.p1 = 1; //a property added into constructor
alert (obj.p1); // “undefined”
alert (obj.constructor. p1); // “1”
obj.__proto__.p2 = 2;
alert(obj.p2); // “2”
A.prototype.p3 = 3;
alert(obj.p3); // “3”
A few more words about prototype and __proto__

dive cheerfully into the code 

Simple object, singleton
var obj =
{
v : "prop"
, AA1 : function(t)
{
alert(this.v + t);
}
}; // "obj" – is "new Object()" that has the keys "v" and "AA1"
obj.AA2 = function(
){
..}; // AA2 key is added to A
obj.AA1(1);
obj.AA2();
Simple class
function A() { this.v = 'prop'; return this; }
A.prototype.AA1 = function(){
};
var obj = new A();
// “v” – property of the obj object
// АА1 – property of the object prototype
A.prototype.AA2 = function(t) { alert(this.v+t); };
obj.AA2(2); // that’s why a1.__proto__ === A.prototype
works
var obj2 = A(); // obj2 is a window
obj2.AA1(1); // which doesn’t have AA1
function A() { return this; }
A.prototype = {
v : 'prop + '
, AA1 : function(){
.}
};
// "A.prototype" turned into "new Object()"
// А.prototype.constructor is not A
var obj = new A();
A.prototype.AA2 = function(){
.};
obj.AA1();
Kill the constructor
Private members
function A()
{
var p1 = 1; // visible inside of “A”
function privateFunction() { p1=2; }
this.v = 'prop';
this.publicFunction = function()
{
privateFunction();
alert(this.v+p1);
}
}
A.prototype.AA1 = function(t){alert(this.v+t)};
var obj = new A();
obj.v = 'new value ';
obj.AA1(3);
obj.publicFunction();
var A = function()
{
var p1 = 1;
function privateFunction() { p1 = 2; }
function B() { return 1; }
B.prototype.v = 'prop ';
B.prototype.publicFunction = function()
{
privateFunction();
}
return B;
}
var obj = new ( A() )();
ĐĄomplex class
var A = (function()
{
var p1 = 1;
function B() {}
B.prototype.setP1 = function(t){p1 = t; }
B.prototype.publicFunction = function() { alert(p1); }
return B;
})();
var obj1 = new A();
obj1.setP1(3);
var obj2 = new A();
obj2.publicFunction(); // alert "3"
Complex singleton
function extend(Child, Parent) {
.} // thx Crockford
function A() { 
.. }
A.prototype.v = 'prop ';
A.prototype.AA1 = function(t){ alert(this.v+t); };
function B()
{
this.z = 2;
B.superclass.constructor.apply(this, arguments);
}
extend(B, A);
var obj = new B();
obj.AA1();
Inheritance
Contact info:
‱ Technical and project manager
‱ Vitali Hornik, PMP¼, Ph.D. in IT (Computer Science)
‱ vhornik@gmail.com

More Related Content

PPTX
Journey of a C# developer into Javascript
PDF
11 2. variable-scope rule,-storage_class
PPTX
2. Design patterns. part #2
PPTX
Storage class in C Language
PDF
Immutability and pure functions
PPTX
Storage classes in C
PPTX
Virtual function
PPTX
Functional programming
Journey of a C# developer into Javascript
11 2. variable-scope rule,-storage_class
2. Design patterns. part #2
Storage class in C Language
Immutability and pure functions
Storage classes in C
Virtual function
Functional programming

What's hot (20)

PPTX
virtual function
DOCX
Check the output of the following code then recode it to eliminate fu
PPTX
Storage classes in C
PPTX
Storage classes
PPT
Storage classes
PPTX
11 lec 11 storage class
DOC
oop Lecture 6
PPTX
Presentation on function
PPTX
Storage class in c
 
PDF
Linq & lambda overview C#.net
DOC
What is storage class
PPTX
Storage Classes and Functions
PDF
Demoiselle 2.0 no JavaOne Brasil 2010
PPT
Advanced JavaScript
PPT
Storage classes
PPTX
Function C++
PPTX
Exception
PPTX
Function (rule in programming)
PPT
storage class
PPTX
Storage class
virtual function
Check the output of the following code then recode it to eliminate fu
Storage classes in C
Storage classes
Storage classes
11 lec 11 storage class
oop Lecture 6
Presentation on function
Storage class in c
 
Linq & lambda overview C#.net
What is storage class
Storage Classes and Functions
Demoiselle 2.0 no JavaOne Brasil 2010
Advanced JavaScript
Storage classes
Function C++
Exception
Function (rule in programming)
storage class
Storage class
Ad

Viewers also liked (10)

PPTX
Files and JavaScript
PDF
PayPal ĐžĐœŃ‚Đ”ĐłŃ€Đ°Ń†ĐžŃ. Đ—Đ°ĐżŃ€Đ”Ń‰Đ”ĐœĐœĐ°Ń лДĐșцоя 18+
PDF
How to become Famo.us
PPTX
CĐŸĐ±Ń‹Ń‚ĐžŃ ĐČ JavaScript
PPTX
Game physics in JavaScript
PDF
ĐŸĐŸŃŃ‚ĐŸŃĐœĐœĐ°Ń ŃĐ±ĐŸŃ€Đșа Ń„Ń€ĐŸĐœŃ‚Đ”ĐœĐŽĐ° – аĐČŃ‚ĐŸĐŒĐ°Ń‚ĐžĐ·Đ°Ń†ĐžŃ ĐșĐŸĐœĐČĐ”ĐčДра
PDF
Production Ready Javascript With Grunt
PPTX
Files and JS
PPTX
Всё лО ты Đ·ĐœĐ°Đ”ŃˆŃŒ ĐŸ JavaScript ООП?
PPTX
Flexbox - ĐČДрстĐșа бДз float'ĐŸĐČ by Dmitry Radyno
Files and JavaScript
PayPal ĐžĐœŃ‚Đ”ĐłŃ€Đ°Ń†ĐžŃ. Đ—Đ°ĐżŃ€Đ”Ń‰Đ”ĐœĐœĐ°Ń лДĐșцоя 18+
How to become Famo.us
CĐŸĐ±Ń‹Ń‚ĐžŃ ĐČ JavaScript
Game physics in JavaScript
ĐŸĐŸŃŃ‚ĐŸŃĐœĐœĐ°Ń ŃĐ±ĐŸŃ€Đșа Ń„Ń€ĐŸĐœŃ‚Đ”ĐœĐŽĐ° – аĐČŃ‚ĐŸĐŒĐ°Ń‚ĐžĐ·Đ°Ń†ĐžŃ ĐșĐŸĐœĐČĐ”ĐčДра
Production Ready Javascript With Grunt
Files and JS
Всё лО ты Đ·ĐœĐ°Đ”ŃˆŃŒ ĐŸ JavaScript ООП?
Flexbox - ĐČДрстĐșа бДз float'ĐŸĐČ by Dmitry Radyno
Ad

Similar to 4front en (20)

PPT
Beginning Object-Oriented JavaScript
PPT
JavaScript In Object Oriented Way
PPTX
Ajaxworld
PPT
Advanced JavaScript
PPT
Advanced Javascript
PPT
Advanced Javascript
PPT
Advanced Javascript
 
PPT
Javascript Object Oriented Programming
KEY
Javascript tid-bits
PPTX
JavsScript OOP
PPTX
Object oriented javascript
PPTX
Framework prototype
 
PPTX
Framework prototype
 
PPTX
Framework prototype
 
PDF
Object Oriented Javascript
PDF
Javascript under the hood 2
PDF
Object Oriented Programming in JavaScript
PPTX
Object Oriented Javascript part2
PDF
JavaScript Inheritance
PPTX
JavaScript OOPS Implimentation
Beginning Object-Oriented JavaScript
JavaScript In Object Oriented Way
Ajaxworld
Advanced JavaScript
Advanced Javascript
Advanced Javascript
Advanced Javascript
 
Javascript Object Oriented Programming
Javascript tid-bits
JavsScript OOP
Object oriented javascript
Framework prototype
 
Framework prototype
 
Framework prototype
 
Object Oriented Javascript
Javascript under the hood 2
Object Oriented Programming in JavaScript
Object Oriented Javascript part2
JavaScript Inheritance
JavaScript OOPS Implimentation

Recently uploaded (20)

PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
top salesforce developer skills in 2025.pdf
PDF
System and Network Administraation Chapter 3
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
L1 - Introduction to python Backend.pptx
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
System and Network Administration Chapter 2
PPTX
Introduction to Artificial Intelligence
PDF
Understanding Forklifts - TECH EHS Solution
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
top salesforce developer skills in 2025.pdf
System and Network Administraation Chapter 3
How to Migrate SBCGlobal Email to Yahoo Easily
Odoo Companies in India – Driving Business Transformation.pdf
Design an Analysis of Algorithms II-SECS-1021-03
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PTS Company Brochure 2025 (1).pdf.......
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Upgrade and Innovation Strategies for SAP ERP Customers
How to Choose the Right IT Partner for Your Business in Malaysia
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
L1 - Introduction to python Backend.pptx
Navsoft: AI-Powered Business Solutions & Custom Software Development
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
How Creative Agencies Leverage Project Management Software.pdf
System and Network Administration Chapter 2
Introduction to Artificial Intelligence
Understanding Forklifts - TECH EHS Solution

4front en

  • 1. Vitali Hornik, PMPÂź Ph.D. in IT (Computer Science) Do you know everything about JavaScript OOP?
  • 2. The main code of procedural programming is constantly processing various situations. The main code of OOP tries to pass responsibility to the executor - system objects. Procedural Programming vs OOP
  • 4. 
and a new project task will make you totally happy! Like this

  • 5. 3 major principles of OOP 1. Encapsulation by means of closures 2. Inheritance via prototyping 3. Polymorphism - JS is not a typed language 
  • 6. 1. interfaces and abstract classes* 2. final classes 3. protected modifiers 4. static class members JS doesn’t have
  • 7. this var obj = { outerWidth : 20 }; function getWidth() { return this.outerWidth; } var a = getWidth (); var b = getWidth.apply(obj); this points to the object in the context of which the code works
  • 8. Can this be changed? 1. var obj = new SomeFunction(
); // the created object 2. obj.publicFunction(
.); // obj 3. someFunction.apply(obj,[arg1,arg2,
.]); // obj 4. someFunction.call(obj, arg1,arg2,
.); // obj
  • 10. prototype and/or __proto__ function A() {
.} A.prototype – an object with one property «constructor». A.prototype.constructor – function А A.__proto__ – Function.prototype, the child of Object. Object is the parent of everything. alert(A.__proto__ === A.prototype.constructor.__proto__ ); // true
  • 11. A Function Object prototype __proto__ prototype __proto__ prototype prototype – specifies the properties of created objects __proto__ – everything has __proto__ , it serves for parent/child connection
  • 12. function A(args) {
.} var obj = new A(args); 1. var obj = {}; 2. obj.__proto__ = A.prototype; 3. var newConstructor = A.apply(obj, [args]); 4. obj = newConstructor instanceof Object ? newConstructor : obj; alert(obj.prototype); // undefined alert(obj.__proto__ === A.prototype); // true alert(obj.__proto__.__proto__ === Object.prototype); // true new
  • 13. var obj = new A(); A.__proto__.p1 = 1; //a property added into constructor alert (obj.p1); // “undefined” alert (obj.constructor. p1); // “1” obj.__proto__.p2 = 2; alert(obj.p2); // “2” A.prototype.p3 = 3; alert(obj.p3); // “3” A few more words about prototype and __proto__
  • 14. 
dive cheerfully into the code 

  • 15. Simple object, singleton var obj = { v : "prop" , AA1 : function(t) { alert(this.v + t); } }; // "obj" – is "new Object()" that has the keys "v" and "AA1" obj.AA2 = function(
){
..}; // AA2 key is added to A obj.AA1(1); obj.AA2();
  • 16. Simple class function A() { this.v = 'prop'; return this; } A.prototype.AA1 = function(){
}; var obj = new A(); // “v” – property of the obj object // АА1 – property of the object prototype A.prototype.AA2 = function(t) { alert(this.v+t); }; obj.AA2(2); // that’s why a1.__proto__ === A.prototype works var obj2 = A(); // obj2 is a window obj2.AA1(1); // which doesn’t have AA1
  • 17. function A() { return this; } A.prototype = { v : 'prop + ' , AA1 : function(){
.} }; // "A.prototype" turned into "new Object()" // А.prototype.constructor is not A var obj = new A(); A.prototype.AA2 = function(){
.}; obj.AA1(); Kill the constructor
  • 18. Private members function A() { var p1 = 1; // visible inside of “A” function privateFunction() { p1=2; } this.v = 'prop'; this.publicFunction = function() { privateFunction(); alert(this.v+p1); } } A.prototype.AA1 = function(t){alert(this.v+t)}; var obj = new A(); obj.v = 'new value '; obj.AA1(3); obj.publicFunction();
  • 19. var A = function() { var p1 = 1; function privateFunction() { p1 = 2; } function B() { return 1; } B.prototype.v = 'prop '; B.prototype.publicFunction = function() { privateFunction(); } return B; } var obj = new ( A() )(); ĐĄomplex class
  • 20. var A = (function() { var p1 = 1; function B() {} B.prototype.setP1 = function(t){p1 = t; } B.prototype.publicFunction = function() { alert(p1); } return B; })(); var obj1 = new A(); obj1.setP1(3); var obj2 = new A(); obj2.publicFunction(); // alert "3" Complex singleton
  • 21. function extend(Child, Parent) {
.} // thx Crockford function A() { 
.. } A.prototype.v = 'prop '; A.prototype.AA1 = function(t){ alert(this.v+t); }; function B() { this.z = 2; B.superclass.constructor.apply(this, arguments); } extend(B, A); var obj = new B(); obj.AA1(); Inheritance
  • 22. Contact info: ‱ Technical and project manager ‱ Vitali Hornik, PMPÂź, Ph.D. in IT (Computer Science) ‱ vhornik@gmail.com