SlideShare a Scribd company logo
Demystifying
 Proto...........
      types
types
null     undefined   number


string   boolean    object
null     undefined   number


string   boolean    object
b.name
     b[“name”]
       “a” in b
  for (var i in b) …
b.hasOwnProperty(“a”)
   b instanceof d
Demystifying Prototypes
function



function f() {};

f();
new f;
function



function f() {};

f();
new f;
function



function f() {};

f();
new f;
Object
Number
String
Boolean
Function
Array
RegExp
Date
A




function A() {};
constructor: A
       A




function A() {};
constructor: A
       A


              b

function A() {};
var b = new A;
constructor: A
       A             x: 1




               b

function A() {};
var b = new A;
A.prototype.x = 1;
constructor: A
       A             x: 1




               b     y: 2



function A() {};
var b = new A;
A.prototype.x = 1;
b.y = 2;
constructor: A
       A             x: 1




        c      b     y: 2



function A() {};
var b = new A;
A.prototype.x = 1;
b.y = 2;
var c = new A;
constructor: A
        A           x: 1




        c      b    y: 2



function A() {};
var b = new A;
A.prototype.x = 1;
b.y = 2;
var c = new A;
A.prototype = {v: 1, w: 2};
v: 1                       constructor: A
w: 2
               A           x: 1




               c      b    y: 2



       function A() {};
       var b = new A;
       A.prototype.x = 1;
       b.y = 2;
       var c = new A;
       A.prototype = {v: 1, w: 2};
v: 1                       constructor: A
w: 2
               A           x: 1




       d       c      b    y: 2



       function A() {};
       var b = new A;
       A.prototype.x = 1;
       b.y = 2;
       var c = new A;
       A.prototype = {v: 1, w: 2};
       var d = new A;
v: 1                    constructor: A
  w: 2
               A     P    x: 1




         d     c     b    y: 2




P.hasOwnProperty(“constructor”)
“constructor” in c
for (var i in P) alert(i);
c.constructor
c instanceof A
d instanceof A
d.constructor
null




           Object




            A


c   d
null




                              Object
function A() {};
function B() {};
B.prototype = new A;
                               A
var d = new B;


                               B


                       d
null




                                    Object
function A() {…};
function B() {};
var Z = function () {};
                                     A
Z.prototype = A.prototype;
B.prototype = new Z;
var d = new B;
                                     B


                             d
null




                                    Object
function A() {…};
function B() {};
var Z = function () {};
                                     A
Z.prototype = A.prototype;
B.prototype = new Z;         Z
var d = new B;
                                     B


                             d
goog.inherits = function(childCtor, parentCtor) {
   /** @constructor */
   function tempCtor() {};
   tempCtor.prototype = parentCtor.prototype;
   childCtor.superClass_ = parentCtor.prototype;
   childCtor.prototype = new tempCtor();
   childCtor.prototype.constructor = childCtor;
};
exports.inherits = function(ctor, superCtor) {
   ctor.super_ = superCtor;
   ctor.prototype = Object.create(superCtor.prototype, {
     constructor: { value: ctor, enumerable: false }
   });
};
null




        Object




       Function




A
null




        Object




       Function




A
JavaScript Paradox




Function.constructor === Function
Thank You


dmitry@baranovskiy.com

More Related Content

PDF
Advanced javascript
PPT
Advanced JavaScript
PPT
Advanced JavaScript
PDF
Exercice java vehicule
PDF
Object Oriented Programming in JavaScript
PDF
Conférence sur les annotations Java par Olivier Croisier (Zenika) au Paris JUG
PPTX
Fondamentaux d’une API REST
PDF
An Introduction to CMake
 
Advanced javascript
Advanced JavaScript
Advanced JavaScript
Exercice java vehicule
Object Oriented Programming in JavaScript
Conférence sur les annotations Java par Olivier Croisier (Zenika) au Paris JUG
Fondamentaux d’une API REST
An Introduction to CMake
 

What's hot (20)

PDF
ZIO-Direct - Functional Scala 2022
PPTX
Simple class and object examples in java
PPTX
Introduction JavaEE
PDF
Javascript under the hood 2
PDF
Polymorphisme, interface et classe abstraite
PDF
Ch 01 poo
PPTX
Bypassing anti virus using powershell
PDF
Advanced heap exploitaion
PPTX
Clean code slide
PPTX
Introduction to git and github
PPTX
OAuth2介紹
PDF
스프링 시큐리티 구조 이해
PPTX
Js: master prototypes
PPT
Présentation Maven
PDF
Chapitre 5 classes abstraites et interfaces
PPTX
Java 11 to 17 : What's new !?
PDF
A Tour of Combine
PPTX
Advanced JavaScript
PDF
Java 8-streams-collectors-patterns
PPTX
Spring boot anane maryem ben aziza syrine
ZIO-Direct - Functional Scala 2022
Simple class and object examples in java
Introduction JavaEE
Javascript under the hood 2
Polymorphisme, interface et classe abstraite
Ch 01 poo
Bypassing anti virus using powershell
Advanced heap exploitaion
Clean code slide
Introduction to git and github
OAuth2介紹
스프링 시큐리티 구조 이해
Js: master prototypes
Présentation Maven
Chapitre 5 classes abstraites et interfaces
Java 11 to 17 : What's new !?
A Tour of Combine
Advanced JavaScript
Java 8-streams-collectors-patterns
Spring boot anane maryem ben aziza syrine
Ad

Similar to Demystifying Prototypes (20)

PPTX
javascript prototype
PDF
JavaScript: enter the dragon
KEY
Javascript3
KEY
Inheritance patterns
PPT
Advanced Javascript
PPT
Advanced Javascript
PPT
Advanced Javascript
PPT
Beginning Object-Oriented JavaScript
PDF
JavaScript Survival Guide
PDF
Js objects
PPTX
Object Oriented JavaScript
PDF
JavaScript Inheritance
PPTX
Typescript barcelona
PDF
Prototype
PDF
The many facets of code reuse in JavaScript
PPT
JavaScript In Object Oriented Way
PPTX
Ian 20150116 java script oop
PDF
Week 06 Modular Javascript_Brandon, S. H. Wu
PDF
JS Level Up: Prototypes
javascript prototype
JavaScript: enter the dragon
Javascript3
Inheritance patterns
Advanced Javascript
Advanced Javascript
Advanced Javascript
Beginning Object-Oriented JavaScript
JavaScript Survival Guide
Js objects
Object Oriented JavaScript
JavaScript Inheritance
Typescript barcelona
Prototype
The many facets of code reuse in JavaScript
JavaScript In Object Oriented Way
Ian 20150116 java script oop
Week 06 Modular Javascript_Brandon, S. H. Wu
JS Level Up: Prototypes
Ad

More from Dmitry Baranovskiy (14)

PDF
The Origins of Magic
PDF
PDF
Type Recognition
PDF
Raphaël JS Conf
PDF
Obvious Secrets of JavaScript
PDF
Your JavaScript Library
PDF
Java Script Workshop
PDF
PDF
Web Vector Graphics
PDF
Typography on the Web
PDF
Microformats—the hidden treasure
PDF
Advanced JavaScript Techniques
The Origins of Magic
Type Recognition
Raphaël JS Conf
Obvious Secrets of JavaScript
Your JavaScript Library
Java Script Workshop
Web Vector Graphics
Typography on the Web
Microformats—the hidden treasure
Advanced JavaScript Techniques

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Approach and Philosophy of On baking technology
PPTX
Big Data Technologies - Introduction.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
KodekX | Application Modernization Development
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
NewMind AI Weekly Chronicles - August'25 Week I
NewMind AI Monthly Chronicles - July 2025
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
“AI and Expert System Decision Support & Business Intelligence Systems”
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Network Security Unit 5.pdf for BCA BBA.
Approach and Philosophy of On baking technology
Big Data Technologies - Introduction.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Machine learning based COVID-19 study performance prediction
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
MYSQL Presentation for SQL database connectivity
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
cuic standard and advanced reporting.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
KodekX | Application Modernization Development
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication

Demystifying Prototypes