SlideShare a Scribd company logo
1 of 62
Anything But Typical Learning to Love JavaScript Prototypes Page 1© 2010 Razorfish. All rights reserved. Dan Nichols March 14, 2010
JavaScript Page 2© 2010 Razorfish. All rights reserved.
Object-Oriented Programming Page 3© 2010 Razorfish. All rights reserved.
class Page 4© 2010 Razorfish. All rights reserved.
Inheritance Page 5© 2010 Razorfish. All rights reserved.
prototype(not the library) Page 6© 2010 Razorfish. All rights reserved.
The story so far… Page 7© 2010 Razorfish. All rights reserved.
<a onclick=“javascript:alert(‘chaos!’)”> Page 8© 2010 Razorfish. All rights reserved.
Page 9© 2010 Razorfish. All rights reserved.
…except it wasn’t all good. Page 10© 2010 Razorfish. All rights reserved.
Page 11© 2010 Razorfish. All rights reserved.
Page 12© 2010 Razorfish. All rights reserved.
Page 13© 2010 Razorfish. All rights reserved.
Page 14© 2010 Razorfish. All rights reserved.
Sound familiar? Page 15© 2010 Razorfish. All rights reserved.
Page 16© 2010 Razorfish. All rights reserved. prototype(not the library) to the rescue!
Page 17© 2010 Razorfish. All rights reserved. Everything is an object
Page 18© 2010 Razorfish. All rights reserved. Every object has a prototype
Page 19© 2010 Razorfish. All rights reserved. prototypes do good things
Page 20© 2010 Razorfish. All rights reserved. Encourage modularityand reusability
Page 21© 2010 Razorfish. All rights reserved. Provide a consistent wayto do (different) things
Page 22© 2010 Razorfish. All rights reserved. Keep code to a minimum
Page 23© 2010 Razorfish. All rights reserved. Make complexity easy
What is a prototype, exactly? Page 24© 2010 Razorfish. All rights reserved.
Page 25© 2010 Razorfish. All rights reserved. A reference point for other objects
Property lookup chain Page 26© 2010 Razorfish. All rights reserved.
Property lookup chain Page 27© 2010 Razorfish. All rights reserved. instance Date Object
Property lookup chain Page 28© 2010 Razorfish. All rights reserved. instance Date Object
Property lookup chain Page 29© 2010 Razorfish. All rights reserved. instance Date Object
Property lookup chain Page 30© 2010 Razorfish. All rights reserved. instance Date Object
Page 31© 2010 Razorfish. All rights reserved. JavaScript is different frommost other OOP languages
Anatomy of a prototype Page 32© 2010 Razorfish. All rights reserved. rex Poodle Dog Object
Anatomy of a prototype Page 33© 2010 Razorfish. All rights reserved. Constructor
Anatomy of a prototype Page 34© 2010 Razorfish. All rights reserved. Property Method
Anatomy of a prototype Page 35© 2010 Razorfish. All rights reserved. Constructor Inheritance
Anatomy of a prototype Page 36© 2010 Razorfish. All rights reserved. Instance Instance Property
this and the lookup chain Page 37© 2010 Razorfish. All rights reserved. fluffy socks Cat Object
this and the lookup chain Page 38© 2010 Razorfish. All rights reserved. socks Cat Object
this and the lookup chain Page 39© 2010 Razorfish. All rights reserved. fluffy Cat Object
Execution context: this and call() Page 40© 2010 Razorfish. All rights reserved.
Execution context: this and call() Page 41© 2010 Razorfish. All rights reserved.
Execution context with instances Page 42© 2010 Razorfish. All rights reserved. Same outcome
Page 43© 2010 Razorfish. All rights reserved. Inheritance
Working with inherited behavior Page 44© 2010 Razorfish. All rights reserved. LimitedContainer Container Object
Working with inherited behavior Page 45© 2010 Razorfish. All rights reserved. LimitedContainer Container Object
Working with inherited behavior Page 46© 2010 Razorfish. All rights reserved. LimitedContainer Container Object
Page 47© 2010 Razorfish. All rights reserved. JavaScript is the Frankensteinof the OOP world
Borrowing from multiple prototypes Page 48© 2010 Razorfish. All rights reserved.
Page 49© 2010 Razorfish. All rights reserved. One small problem
The constructor problem Page 50© 2010 Razorfish. All rights reserved.
The constructor problem Page 51© 2010 Razorfish. All rights reserved.
Fixing the constructor problem Page 52© 2010 Razorfish. All rights reserved.
Fixing the constructor problem Page 53© 2010 Razorfish. All rights reserved.
Page 54© 2010 Razorfish. All rights reserved. prototype isn’t love at first sight
Page 55© 2010 Razorfish. All rights reserved. Putting prototypes to work
Requirements ,[object Object]
Required
Email
Number
Zip Code
 Multiple rules can apply to one field
 Rules need to be inferred from  data-rich, standard HTML

More Related Content

Viewers also liked

ClientSummit2010_EricJillard(Mercedes)
ClientSummit2010_EricJillard(Mercedes)ClientSummit2010_EricJillard(Mercedes)
ClientSummit2010_EricJillard(Mercedes)Razorfish
 
ClientSummit2010_MikeBoylson(JCPenney)
ClientSummit2010_MikeBoylson(JCPenney)ClientSummit2010_MikeBoylson(JCPenney)
ClientSummit2010_MikeBoylson(JCPenney)Razorfish
 
2010 Razorfish Outlook Report
2010 Razorfish Outlook Report2010 Razorfish Outlook Report
2010 Razorfish Outlook ReportRazorfish
 
Razorfish & CafeMom - Digital Mom
Razorfish & CafeMom - Digital MomRazorfish & CafeMom - Digital Mom
Razorfish & CafeMom - Digital MomRazorfish
 
Sleeping Giants: Digital Awakens TV and Media
Sleeping Giants: Digital Awakens TV and MediaSleeping Giants: Digital Awakens TV and Media
Sleeping Giants: Digital Awakens TV and MediaRazorfish
 
ClientSummit2010_JohanJervoe(Intel)
ClientSummit2010_JohanJervoe(Intel)ClientSummit2010_JohanJervoe(Intel)
ClientSummit2010_JohanJervoe(Intel)Razorfish
 
Razorfish outlook report 2011 (vol10)
Razorfish outlook report 2011 (vol10)Razorfish outlook report 2011 (vol10)
Razorfish outlook report 2011 (vol10)Luis Miranda
 
Fluent: The Razorfish Social Influence Marketing Report
Fluent: The Razorfish Social Influence Marketing ReportFluent: The Razorfish Social Influence Marketing Report
Fluent: The Razorfish Social Influence Marketing ReportRazorfish
 
Creative Sponge - Agency Credentials
Creative Sponge - Agency CredentialsCreative Sponge - Agency Credentials
Creative Sponge - Agency Credentialsalextosh
 

Viewers also liked (9)

ClientSummit2010_EricJillard(Mercedes)
ClientSummit2010_EricJillard(Mercedes)ClientSummit2010_EricJillard(Mercedes)
ClientSummit2010_EricJillard(Mercedes)
 
ClientSummit2010_MikeBoylson(JCPenney)
ClientSummit2010_MikeBoylson(JCPenney)ClientSummit2010_MikeBoylson(JCPenney)
ClientSummit2010_MikeBoylson(JCPenney)
 
2010 Razorfish Outlook Report
2010 Razorfish Outlook Report2010 Razorfish Outlook Report
2010 Razorfish Outlook Report
 
Razorfish & CafeMom - Digital Mom
Razorfish & CafeMom - Digital MomRazorfish & CafeMom - Digital Mom
Razorfish & CafeMom - Digital Mom
 
Sleeping Giants: Digital Awakens TV and Media
Sleeping Giants: Digital Awakens TV and MediaSleeping Giants: Digital Awakens TV and Media
Sleeping Giants: Digital Awakens TV and Media
 
ClientSummit2010_JohanJervoe(Intel)
ClientSummit2010_JohanJervoe(Intel)ClientSummit2010_JohanJervoe(Intel)
ClientSummit2010_JohanJervoe(Intel)
 
Razorfish outlook report 2011 (vol10)
Razorfish outlook report 2011 (vol10)Razorfish outlook report 2011 (vol10)
Razorfish outlook report 2011 (vol10)
 
Fluent: The Razorfish Social Influence Marketing Report
Fluent: The Razorfish Social Influence Marketing ReportFluent: The Razorfish Social Influence Marketing Report
Fluent: The Razorfish Social Influence Marketing Report
 
Creative Sponge - Agency Credentials
Creative Sponge - Agency CredentialsCreative Sponge - Agency Credentials
Creative Sponge - Agency Credentials
 

Similar to Anything But Typical: Learning to Love JavaScript Prototypes

The Ajax Experience: State Of The Browsers
The Ajax Experience: State Of The BrowsersThe Ajax Experience: State Of The Browsers
The Ajax Experience: State Of The BrowsersPeter-Paul Koch
 
JavaScript: You Like It, It Likes You
JavaScript: You Like It, It Likes YouJavaScript: You Like It, It Likes You
JavaScript: You Like It, It Likes YouScott Kosman
 
JavaScript nicht nur für Programmierer: Einblicke in die weltweit am meisten ...
JavaScript nicht nur für Programmierer: Einblicke in die weltweit am meisten ...JavaScript nicht nur für Programmierer: Einblicke in die weltweit am meisten ...
JavaScript nicht nur für Programmierer: Einblicke in die weltweit am meisten ...Peter Hecker
 
Lotico oct 2010
Lotico oct 2010Lotico oct 2010
Lotico oct 2010dallemang
 
주로사용되는 Xss필터와 이를 공격하는 방법
주로사용되는 Xss필터와 이를 공격하는 방법주로사용되는 Xss필터와 이를 공격하는 방법
주로사용되는 Xss필터와 이를 공격하는 방법guestad13b55
 
IPTC News in JSON Spring 2013
IPTC News in JSON Spring 2013IPTC News in JSON Spring 2013
IPTC News in JSON Spring 2013Stuart Myles
 
Google ARが提供する WebAR 101
Google ARが提供する WebAR 101Google ARが提供する WebAR 101
Google ARが提供する WebAR 101Hirokazu Egashira
 
Real-time Semantic Web with Twitter Annotations
Real-time Semantic Web with Twitter AnnotationsReal-time Semantic Web with Twitter Annotations
Real-time Semantic Web with Twitter AnnotationsJoshua Shinavier
 
Securing Web Applications
Securing Web ApplicationsSecuring Web Applications
Securing Web Applicationsgoodfriday
 
Finding harmony in web development
Finding harmony in web developmentFinding harmony in web development
Finding harmony in web developmentChristian Heilmann
 
Why Rust? by Edd Barrett (codeHarbour December 2019)
Why Rust? by Edd Barrett (codeHarbour December 2019)Why Rust? by Edd Barrett (codeHarbour December 2019)
Why Rust? by Edd Barrett (codeHarbour December 2019)Alex Cachia
 
Web browsers & the realtime web
Web browsers & the realtime webWeb browsers & the realtime web
Web browsers & the realtime webPhil Leggetter
 
JavaScript Internationalization I18n for Efficient Software Localization
JavaScript Internationalization I18n for Efficient Software LocalizationJavaScript Internationalization I18n for Efficient Software Localization
JavaScript Internationalization I18n for Efficient Software LocalizationLingoport (www.lingoport.com)
 
Webpack & EcmaScript 6 (Webelement #32)
Webpack & EcmaScript 6 (Webelement #32)Webpack & EcmaScript 6 (Webelement #32)
Webpack & EcmaScript 6 (Webelement #32)srigi
 

Similar to Anything But Typical: Learning to Love JavaScript Prototypes (20)

The Ajax Experience: State Of The Browsers
The Ajax Experience: State Of The BrowsersThe Ajax Experience: State Of The Browsers
The Ajax Experience: State Of The Browsers
 
JavaScript: You Like It, It Likes You
JavaScript: You Like It, It Likes YouJavaScript: You Like It, It Likes You
JavaScript: You Like It, It Likes You
 
JavaScript nicht nur für Programmierer: Einblicke in die weltweit am meisten ...
JavaScript nicht nur für Programmierer: Einblicke in die weltweit am meisten ...JavaScript nicht nur für Programmierer: Einblicke in die weltweit am meisten ...
JavaScript nicht nur für Programmierer: Einblicke in die weltweit am meisten ...
 
Lotico oct 2010
Lotico oct 2010Lotico oct 2010
Lotico oct 2010
 
All of javascript
All of javascriptAll of javascript
All of javascript
 
주로사용되는 Xss필터와 이를 공격하는 방법
주로사용되는 Xss필터와 이를 공격하는 방법주로사용되는 Xss필터와 이를 공격하는 방법
주로사용되는 Xss필터와 이를 공격하는 방법
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
IPTC News in JSON Spring 2013
IPTC News in JSON Spring 2013IPTC News in JSON Spring 2013
IPTC News in JSON Spring 2013
 
Google ARが提供する WebAR 101
Google ARが提供する WebAR 101Google ARが提供する WebAR 101
Google ARが提供する WebAR 101
 
Real-time Semantic Web with Twitter Annotations
Real-time Semantic Web with Twitter AnnotationsReal-time Semantic Web with Twitter Annotations
Real-time Semantic Web with Twitter Annotations
 
Securing Web Applications
Securing Web ApplicationsSecuring Web Applications
Securing Web Applications
 
Adobemax2009na
Adobemax2009naAdobemax2009na
Adobemax2009na
 
Finding harmony in web development
Finding harmony in web developmentFinding harmony in web development
Finding harmony in web development
 
All of Javascript
All of JavascriptAll of Javascript
All of Javascript
 
Why Rust? by Edd Barrett (codeHarbour December 2019)
Why Rust? by Edd Barrett (codeHarbour December 2019)Why Rust? by Edd Barrett (codeHarbour December 2019)
Why Rust? by Edd Barrett (codeHarbour December 2019)
 
Python basics
Python basicsPython basics
Python basics
 
Web browsers & the realtime web
Web browsers & the realtime webWeb browsers & the realtime web
Web browsers & the realtime web
 
JavaScript Internationalization I18n for Efficient Software Localization
JavaScript Internationalization I18n for Efficient Software LocalizationJavaScript Internationalization I18n for Efficient Software Localization
JavaScript Internationalization I18n for Efficient Software Localization
 
Webpack & EcmaScript 6 (Webelement #32)
Webpack & EcmaScript 6 (Webelement #32)Webpack & EcmaScript 6 (Webelement #32)
Webpack & EcmaScript 6 (Webelement #32)
 
Look beyond PHP
Look beyond PHPLook beyond PHP
Look beyond PHP
 

More from Razorfish

ClientSummit2010_HendersonPetrillo(SkilletStreetFood)
ClientSummit2010_HendersonPetrillo(SkilletStreetFood)ClientSummit2010_HendersonPetrillo(SkilletStreetFood)
ClientSummit2010_HendersonPetrillo(SkilletStreetFood)Razorfish
 
ClientSummit2010_MathiasSinn(McDonalds-NeueDigitale)
ClientSummit2010_MathiasSinn(McDonalds-NeueDigitale)ClientSummit2010_MathiasSinn(McDonalds-NeueDigitale)
ClientSummit2010_MathiasSinn(McDonalds-NeueDigitale)Razorfish
 
ClientSummit2010_RussellTaylor(AxeCaseStudies)
ClientSummit2010_RussellTaylor(AxeCaseStudies)ClientSummit2010_RussellTaylor(AxeCaseStudies)
ClientSummit2010_RussellTaylor(AxeCaseStudies)Razorfish
 
ClientSummit2010_MediaMixWorkshop
ClientSummit2010_MediaMixWorkshopClientSummit2010_MediaMixWorkshop
ClientSummit2010_MediaMixWorkshopRazorfish
 
ClientSummit2010_SearchWorkshop
ClientSummit2010_SearchWorkshopClientSummit2010_SearchWorkshop
ClientSummit2010_SearchWorkshopRazorfish
 
ClientSummit2010_CloudWorkshop
ClientSummit2010_CloudWorkshopClientSummit2010_CloudWorkshop
ClientSummit2010_CloudWorkshopRazorfish
 
ClientSummit2010_AgileWorkshop
ClientSummit2010_AgileWorkshopClientSummit2010_AgileWorkshop
ClientSummit2010_AgileWorkshopRazorfish
 
ClientSummit2010_MobileWorkshop
ClientSummit2010_MobileWorkshopClientSummit2010_MobileWorkshop
ClientSummit2010_MobileWorkshopRazorfish
 
2010 Razorfish Outlook Report
2010 Razorfish Outlook Report2010 Razorfish Outlook Report
2010 Razorfish Outlook ReportRazorfish
 
2010 Razorfish Outlook Report
2010 Razorfish Outlook Report2010 Razorfish Outlook Report
2010 Razorfish Outlook ReportRazorfish
 
2010 Razorfish Outlook Report
2010 Razorfish Outlook Report2010 Razorfish Outlook Report
2010 Razorfish Outlook ReportRazorfish
 
A Decade in Search
A Decade in SearchA Decade in Search
A Decade in SearchRazorfish
 
Social Influence Marketing Trends
Social Influence Marketing TrendsSocial Influence Marketing Trends
Social Influence Marketing TrendsRazorfish
 
FEED: The Razorfish Digital Brand Experience Report 2009 Key Findings
FEED: The Razorfish Digital Brand Experience Report 2009 Key FindingsFEED: The Razorfish Digital Brand Experience Report 2009 Key Findings
FEED: The Razorfish Digital Brand Experience Report 2009 Key FindingsRazorfish
 
FEED: The Razorfish Digital Brand Experience Report 2009
FEED: The Razorfish Digital Brand Experience Report 2009FEED: The Razorfish Digital Brand Experience Report 2009
FEED: The Razorfish Digital Brand Experience Report 2009Razorfish
 
Highlights From Fluent
Highlights From FluentHighlights From Fluent
Highlights From FluentRazorfish
 
Design Matters: A Mobile UX Manifesto
Design Matters: A Mobile UX ManifestoDesign Matters: A Mobile UX Manifesto
Design Matters: A Mobile UX ManifestoRazorfish
 

More from Razorfish (17)

ClientSummit2010_HendersonPetrillo(SkilletStreetFood)
ClientSummit2010_HendersonPetrillo(SkilletStreetFood)ClientSummit2010_HendersonPetrillo(SkilletStreetFood)
ClientSummit2010_HendersonPetrillo(SkilletStreetFood)
 
ClientSummit2010_MathiasSinn(McDonalds-NeueDigitale)
ClientSummit2010_MathiasSinn(McDonalds-NeueDigitale)ClientSummit2010_MathiasSinn(McDonalds-NeueDigitale)
ClientSummit2010_MathiasSinn(McDonalds-NeueDigitale)
 
ClientSummit2010_RussellTaylor(AxeCaseStudies)
ClientSummit2010_RussellTaylor(AxeCaseStudies)ClientSummit2010_RussellTaylor(AxeCaseStudies)
ClientSummit2010_RussellTaylor(AxeCaseStudies)
 
ClientSummit2010_MediaMixWorkshop
ClientSummit2010_MediaMixWorkshopClientSummit2010_MediaMixWorkshop
ClientSummit2010_MediaMixWorkshop
 
ClientSummit2010_SearchWorkshop
ClientSummit2010_SearchWorkshopClientSummit2010_SearchWorkshop
ClientSummit2010_SearchWorkshop
 
ClientSummit2010_CloudWorkshop
ClientSummit2010_CloudWorkshopClientSummit2010_CloudWorkshop
ClientSummit2010_CloudWorkshop
 
ClientSummit2010_AgileWorkshop
ClientSummit2010_AgileWorkshopClientSummit2010_AgileWorkshop
ClientSummit2010_AgileWorkshop
 
ClientSummit2010_MobileWorkshop
ClientSummit2010_MobileWorkshopClientSummit2010_MobileWorkshop
ClientSummit2010_MobileWorkshop
 
2010 Razorfish Outlook Report
2010 Razorfish Outlook Report2010 Razorfish Outlook Report
2010 Razorfish Outlook Report
 
2010 Razorfish Outlook Report
2010 Razorfish Outlook Report2010 Razorfish Outlook Report
2010 Razorfish Outlook Report
 
2010 Razorfish Outlook Report
2010 Razorfish Outlook Report2010 Razorfish Outlook Report
2010 Razorfish Outlook Report
 
A Decade in Search
A Decade in SearchA Decade in Search
A Decade in Search
 
Social Influence Marketing Trends
Social Influence Marketing TrendsSocial Influence Marketing Trends
Social Influence Marketing Trends
 
FEED: The Razorfish Digital Brand Experience Report 2009 Key Findings
FEED: The Razorfish Digital Brand Experience Report 2009 Key FindingsFEED: The Razorfish Digital Brand Experience Report 2009 Key Findings
FEED: The Razorfish Digital Brand Experience Report 2009 Key Findings
 
FEED: The Razorfish Digital Brand Experience Report 2009
FEED: The Razorfish Digital Brand Experience Report 2009FEED: The Razorfish Digital Brand Experience Report 2009
FEED: The Razorfish Digital Brand Experience Report 2009
 
Highlights From Fluent
Highlights From FluentHighlights From Fluent
Highlights From Fluent
 
Design Matters: A Mobile UX Manifesto
Design Matters: A Mobile UX ManifestoDesign Matters: A Mobile UX Manifesto
Design Matters: A Mobile UX Manifesto
 

Recently uploaded

It will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayIt will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayNZSG
 
Socio-economic-Impact-of-business-consumers-suppliers-and.pptx
Socio-economic-Impact-of-business-consumers-suppliers-and.pptxSocio-economic-Impact-of-business-consumers-suppliers-and.pptx
Socio-economic-Impact-of-business-consumers-suppliers-and.pptxtrishalcan8
 
RE Capital's Visionary Leadership under Newman Leech
RE Capital's Visionary Leadership under Newman LeechRE Capital's Visionary Leadership under Newman Leech
RE Capital's Visionary Leadership under Newman LeechNewman George Leech
 
Catalogue ONG NUOC PPR DE NHAT .pdf
Catalogue ONG NUOC PPR DE NHAT      .pdfCatalogue ONG NUOC PPR DE NHAT      .pdf
Catalogue ONG NUOC PPR DE NHAT .pdfOrient Homes
 
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779Delhi Call girls
 
DEPED Work From Home WORKWEEK-PLAN.docx
DEPED Work From Home  WORKWEEK-PLAN.docxDEPED Work From Home  WORKWEEK-PLAN.docx
DEPED Work From Home WORKWEEK-PLAN.docxRodelinaLaud
 
VIP Kolkata Call Girl Howrah 👉 8250192130 Available With Room
VIP Kolkata Call Girl Howrah 👉 8250192130  Available With RoomVIP Kolkata Call Girl Howrah 👉 8250192130  Available With Room
VIP Kolkata Call Girl Howrah 👉 8250192130 Available With Roomdivyansh0kumar0
 
7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...Paul Menig
 
Call Girls in Gomti Nagar - 7388211116 - With room Service
Call Girls in Gomti Nagar - 7388211116  - With room ServiceCall Girls in Gomti Nagar - 7388211116  - With room Service
Call Girls in Gomti Nagar - 7388211116 - With room Servicediscovermytutordmt
 
Monte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMMonte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMRavindra Nath Shukla
 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdfRenandantas16
 
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service JamshedpurVIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service JamshedpurSuhani Kapoor
 
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...Lviv Startup Club
 
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒anilsa9823
 
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Dipal Arora
 
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...lizamodels9
 
GD Birla and his contribution in management
GD Birla and his contribution in managementGD Birla and his contribution in management
GD Birla and his contribution in managementchhavia330
 

Recently uploaded (20)

KestrelPro Flyer Japan IT Week 2024 (English)
KestrelPro Flyer Japan IT Week 2024 (English)KestrelPro Flyer Japan IT Week 2024 (English)
KestrelPro Flyer Japan IT Week 2024 (English)
 
It will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayIt will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 May
 
Socio-economic-Impact-of-business-consumers-suppliers-and.pptx
Socio-economic-Impact-of-business-consumers-suppliers-and.pptxSocio-economic-Impact-of-business-consumers-suppliers-and.pptx
Socio-economic-Impact-of-business-consumers-suppliers-and.pptx
 
RE Capital's Visionary Leadership under Newman Leech
RE Capital's Visionary Leadership under Newman LeechRE Capital's Visionary Leadership under Newman Leech
RE Capital's Visionary Leadership under Newman Leech
 
Catalogue ONG NUOC PPR DE NHAT .pdf
Catalogue ONG NUOC PPR DE NHAT      .pdfCatalogue ONG NUOC PPR DE NHAT      .pdf
Catalogue ONG NUOC PPR DE NHAT .pdf
 
Best Practices for Implementing an External Recruiting Partnership
Best Practices for Implementing an External Recruiting PartnershipBest Practices for Implementing an External Recruiting Partnership
Best Practices for Implementing an External Recruiting Partnership
 
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
 
DEPED Work From Home WORKWEEK-PLAN.docx
DEPED Work From Home  WORKWEEK-PLAN.docxDEPED Work From Home  WORKWEEK-PLAN.docx
DEPED Work From Home WORKWEEK-PLAN.docx
 
VIP Kolkata Call Girl Howrah 👉 8250192130 Available With Room
VIP Kolkata Call Girl Howrah 👉 8250192130  Available With RoomVIP Kolkata Call Girl Howrah 👉 8250192130  Available With Room
VIP Kolkata Call Girl Howrah 👉 8250192130 Available With Room
 
7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...
 
Call Girls in Gomti Nagar - 7388211116 - With room Service
Call Girls in Gomti Nagar - 7388211116  - With room ServiceCall Girls in Gomti Nagar - 7388211116  - With room Service
Call Girls in Gomti Nagar - 7388211116 - With room Service
 
Monte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMMonte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSM
 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
 
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service JamshedpurVIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
 
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
 
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
 
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
 
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
 
GD Birla and his contribution in management
GD Birla and his contribution in managementGD Birla and his contribution in management
GD Birla and his contribution in management
 
Forklift Operations: Safety through Cartoons
Forklift Operations: Safety through CartoonsForklift Operations: Safety through Cartoons
Forklift Operations: Safety through Cartoons
 

Anything But Typical: Learning to Love JavaScript Prototypes

Editor's Notes

  1. Web was a scary placeBrowser compatibility and features all over the mapDevs hop from site to site grabbing snippets of code
  2. JS libraries emerge several years agoSmooth over cross browser differencesMake complex behavior easyProvide frameworks for enhancement
  3. New dependency on libraries and plugins is growingDevs spend a lot of time… (series)
  4. Searching for a JS library extension that does what they need
  5. Changing site to fit what the extension does
  6. Brute-force coding requirements back in
  7. Live in fear of repeating it allwhen make updateson the next project
  8. One of JS most powerful featues goesUnusedIgnoredMisunderstoodAnd it can help
  9. JS is OOP language
  10. Objects are containers forProperties - DataMethods - BehaviorsWork with objects all the time
  11. Template for properties + methodsWork with prototypes every dayEven if you don’t realize itDate, Array, etc
  12. Code you writeCode loaded in memory
  13. Easy to…BuildModifyExpand on complex interactions
  14. Reference point that serves as basis for an objectTo understand prototypeNeed to understand property lookup chain
  15. Simple exampleCreate a date var named “instance”Define a new property on the varCall several methods
  16. PLC for instance var looks like thisInstance prototype = DateDate prototype = ObjectJS uses PLC to find values of referenced properties
  17. Look up instance.fooJS finds it on the var itselfStops looking
  18. Lookup instance.getTimeDoesn’t find it on the varFinds it on DateStops looking
  19. Lookup instance.hasOwnPropertyDoesn’t find it on varDoesn’t find it on DateFinds it on Object
  20. Prototypes are put together different than most
  21. More complicated exampleRex is var instance of PoodlePoodle prototype = DogDog prototype = Object
  22. Closer look at DogFunctionAll functions have prototype propertyPrototype defaults to ObjectConstructor is Function paired with NEW operatorUsed to create instances
  23. Dog’s prototype property used to build the templateFunctions on a prototype are methodsNon-functions on a prototype are propertiesAnything defined on function’s prototype available to instances
  24. Poodle is second typeFunction, just like DogInheritanceSet Poodle.prototype to new instance of DogCreates link between Poodle and Dog in PLCCreate properties on Poodle.prototypeAvailable to instances of Poodle
  25. Rex is instance of PoodleProperty “name” defined on rex – instance propertyHas access to all of Poodle’s prototype propertiesAnd to other properties up PLC
  26. Probably recognize THIS operatorLook at how THIS interacts with prototypeIn example:Socks and fluffy both instances of CatCat inherits from Object
  27. When call socks.speakFinds speak property on Cat.prototypeInside of speak, encounter THISProperties on THIS walk PLC starting at instanceGreeting not a property of socks instanceGreeting is a property of Cat prototype
  28. When call fluffy.speakSpeak function found on Cat.prototype, same as socksUnlike socks, fluffy has own greeting propertylookup stops at instance
  29. Functions have call method that lets set execution contextTHIS operator refers back to execution context
  30. When sayFoo called with exec context objTHIS = obj
  31. Calling a method on an instance is same asUsing CALL to supply instance as exec context prototype method
  32. Shown some basic examples so far, but don’t really take advantageDive deeper into inheritance
  33. In example:Container type hasarray that it can store items inMethod to add itemsinherits from ObjectLimitedContainerInherits from ContainerChanges inherited behavior to limit how many items can be in array
  34. Behavior in Container constructor creates items arrayTo get LC to also have that behaviorCALL Container constructor with THIS as exec context within LC constructor
  35. Container’s addItem method just pushes into arrayWant to set a limit to how many items can be in arrayDefine new addItem method on LC prototypeThe new addItem is higher in the PLC, so it will be found before old oneAdd logic into new method to throw error if there are too many itemsCALL Container’s addItem method with THIS as exec context to get original behavior
  36. Have kind of a patchwork natureCan take advantage of that to bring together lots of complicated behaviors
  37. In example, CatDog borrows behavior from Cat and DogCat instances are furious when call swim methodDog instances are delightedCatDog is both delighted and furious when you call its swim method
  38. May have noticed an issue in earlier examples
  39. Have two types: Parent and ChildChild inherits from parent
  40. When Child linked to ParentParent constructor is calledParent constructor has undesirable behaviorAlert goes off when set up inheritance
  41. Get around issue with a simple helper function
  42. Helper:Creates intermediate function that does nothingAssigns parent prototype to itInstantiates intermediate as prototypeBecause prototype is same b/t intermediate and parent, PLC stays intactAlso define constructor on child while we’re at itNo more undesirable behavior
  43. Prototypes have never been accused of being very prettyBut they are very powerful
  44. Up to now, haven’t had any real world examplesLet’s see what they can really doEXAMPLEPretty standard HTML formCommon problem is validating a formLet’s do it with prototypes!
  45. Helper:Creates intermediate function that does nothingAssigns parent prototype to itInstantiates intermediate as prototypeBecause prototype is same b/t intermediate and parent, PLC stays intactAlso define constructor on child while we’re at itNo more undesirable behavior
  46. Helper:Creates intermediate function that does nothingAssigns parent prototype to itInstantiates intermediate as prototypeBecause prototype is same b/t intermediate and parent, PLC stays intactAlso define constructor on child while we’re at itNo more undesirable behavior
  47. And do a really good job of itStart to get into trouble when depend totally on the libraryStart to get into bad trouble when depending totally on plugins
  48. Easy to…BuildModifyExpand on complex interactions
  49. Help you design the interactionthe way it needs to workand in a reusable, extensible way that plays well with others
  50. Any questions?