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
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

What's hot

Learn REST API with Python
Learn REST API with PythonLearn REST API with Python
Learn REST API with Python
Larry Cai
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!
Jakub Kubrynski
 

What's hot (20)

Learn REST API with Python
Learn REST API with PythonLearn REST API with Python
Learn REST API with Python
 
Javascript Prototype Visualized
Javascript Prototype VisualizedJavascript Prototype Visualized
Javascript Prototype Visualized
 
Javascript this keyword
Javascript this keywordJavascript this keyword
Javascript this keyword
 
Js: master prototypes
Js: master prototypesJs: master prototypes
Js: master prototypes
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6
 
A journey beyond the page object pattern
A journey beyond the page object patternA journey beyond the page object pattern
A journey beyond the page object pattern
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event Handling
 
Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2
 
Mockito a simple, intuitive mocking framework
Mockito   a simple, intuitive mocking frameworkMockito   a simple, intuitive mocking framework
Mockito a simple, intuitive mocking framework
 
ES6 presentation
ES6 presentationES6 presentation
ES6 presentation
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
 
Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.
 
Kiss PageObjects [01-2017]
Kiss PageObjects [01-2017]Kiss PageObjects [01-2017]
Kiss PageObjects [01-2017]
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
JavaScript Fetch API
JavaScript Fetch APIJavaScript Fetch API
JavaScript Fetch API
 
Sharing Data Between Angular Components
Sharing Data Between Angular ComponentsSharing Data Between Angular Components
Sharing Data Between Angular Components
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!
 
간단한 블로그를 만들며 Django 이해하기
간단한 블로그를 만들며 Django 이해하기간단한 블로그를 만들며 Django 이해하기
간단한 블로그를 만들며 Django 이해하기
 
Angular Advanced Routing
Angular Advanced RoutingAngular Advanced Routing
Angular Advanced Routing
 
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
 

Similar to Demystifying Prototypes

Inheritance patterns
Inheritance patternsInheritance patterns
Inheritance patterns
Luke Smith
 
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6  1ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6  1
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1
Little Tukta Lita
 
(Polymorphism-OperatorOverLoadingUsingFriendFunction).pdf
(Polymorphism-OperatorOverLoadingUsingFriendFunction).pdf(Polymorphism-OperatorOverLoadingUsingFriendFunction).pdf
(Polymorphism-OperatorOverLoadingUsingFriendFunction).pdf
AakashBerlia1
 
Javascript3
Javascript3Javascript3
Javascript3
mozks
 

Similar to Demystifying Prototypes (20)

F(1)
F(1)F(1)
F(1)
 
manager
managermanager
manager
 
Inheritance patterns
Inheritance patternsInheritance patterns
Inheritance patterns
 
4front en
4front en4front en
4front en
 
Ştiri de ultima ora si ultimele ştiri Vdtonline.com
Ştiri de ultima ora si ultimele ştiri Vdtonline.comŞtiri de ultima ora si ultimele ştiri Vdtonline.com
Ştiri de ultima ora si ultimele ştiri Vdtonline.com
 
F(3)
F(3)F(3)
F(3)
 
Java Script Workshop
Java Script WorkshopJava Script Workshop
Java Script Workshop
 
JavaScript: enter the dragon
JavaScript: enter the dragonJavaScript: enter the dragon
JavaScript: enter the dragon
 
javascript prototype
javascript prototypejavascript prototype
javascript prototype
 
Vdtonline
VdtonlineVdtonline
Vdtonline
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6  1ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6  1
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1
 
JavaScript Object API
JavaScript Object APIJavaScript Object API
JavaScript Object API
 
Lecture 4: Data Types
Lecture 4: Data TypesLecture 4: Data Types
Lecture 4: Data Types
 
D1
D1D1
D1
 
F(1)
F(1)F(1)
F(1)
 
Advanced JavaScript
Advanced JavaScript Advanced JavaScript
Advanced JavaScript
 
Java programs
Java programsJava programs
Java programs
 
(Polymorphism-OperatorOverLoadingUsingFriendFunction).pdf
(Polymorphism-OperatorOverLoadingUsingFriendFunction).pdf(Polymorphism-OperatorOverLoadingUsingFriendFunction).pdf
(Polymorphism-OperatorOverLoadingUsingFriendFunction).pdf
 
Javascript3
Javascript3Javascript3
Javascript3
 

More from Dmitry Baranovskiy (13)

The Origins of Magic
The Origins of MagicThe Origins of Magic
The Origins of Magic
 
Raphaël
RaphaëlRaphaël
Raphaël
 
Type Recognition
Type RecognitionType Recognition
Type Recognition
 
Raphaël JS Conf
Raphaël JS ConfRaphaël JS Conf
Raphaël JS Conf
 
Obvious Secrets of JavaScript
Obvious Secrets of JavaScriptObvious Secrets of JavaScript
Obvious Secrets of JavaScript
 
Your JavaScript Library
Your JavaScript LibraryYour JavaScript Library
Your JavaScript Library
 
Canvas
CanvasCanvas
Canvas
 
SVG
SVGSVG
SVG
 
Raphael
RaphaelRaphael
Raphael
 
Web Vector Graphics
Web Vector GraphicsWeb Vector Graphics
Web Vector Graphics
 
Typography on the Web
Typography on the WebTypography on the Web
Typography on the Web
 
Microformats—the hidden treasure
Microformats—the hidden treasureMicroformats—the hidden treasure
Microformats—the hidden treasure
 
Advanced JavaScript Techniques
Advanced JavaScript TechniquesAdvanced JavaScript Techniques
Advanced JavaScript Techniques
 

Recently uploaded

Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 

Recently uploaded (20)

UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT Professionals
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG Evaluation
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 

Demystifying Prototypes