SlideShare a Scribd company logo
Alipay Inc


     Understand Prototype



                      颂赞
             (http://qiqicartoon.com)
Alipay Inc


• What is prototype?
• How to inherit?
• Simple Object
• Defining a Class
• Defining and Calling method in Class
• Calling the SuperClass from SubClass
• Overriding Method of SuperClass in SubClass
• Calling Method of SuperClass from SubClass
Alipay Inc


       What is prototype?
     By ECMASCRIPT: Each constructor is a function
     that has a property named ―prototype that is
     used to implement prototype-based inheritance
     and shared properties.
Alipay Inc


    Prototype is prototype?

     Prototype contain:
     • Prototype property
     • Prototype object
Alipay Inc


       What is prototype?
     function User(){
       //…
     }                    Prototype property
     User.prototype = {
       //methods…
     };
                          Prototype object
Alipay Inc


       What is prototype?
     Prototype object也是类成员的集合
Alipay Inc

       What is prototype?
      Array, Object, Number, Function, Null, Undefind
              function _arrayObj(){}

              Array.prototype = new _arrayObj();
              console.log(Array.prototype.constructor) ;//Array,not Function

              var userName = ‘zhuiq’,
                  companies = [‘alipay’,’alisoft’],
                  friends = {
                      ‘a’:{},’b’:{}
                  };

              userName.prototype = {};//?
              companies.prototype = {};//?
              friends.prototype = {};//?
              null.prototype //?
              undefined.prototype //?
Alipay Inc

       What is prototype?
Javascript原始对象的prototype是只读的!
只有函数对象才有prototype属性!
Alipay Inc

         What is prototype?
                                methods
                                • __defineGetter__
                                • __defineSetter__
                                • eval
                                • hasOwnProperty
                                • isPrototypeOf
                                • valueOf
   Prototype                    • watch
    Object                      • unwatch
                                • toString
                properties      • toSource
                                • propertyIsEnumerable
                • constructor   • __noSuchMethod__
                • __parent__    • __lookupGetter__
                • __proto__     • __lookupSetter__
                • __count__
Alipay Inc


             How to inherit?
PHP: extends
JAVA: extends
Ruby: <
ASP: :
Python: class subClassName(SuperClassName)
C++: :
Javascript: prototype
Alipay Inc


             How to inherit?
Alipay Inc


               How to inherit?
   var CF= function (){},
       CFp = {CFP1:1,CFP2:2};

   CF.prototype = CFp;
   CF.prototype.P1 = ‘P1’;
   CF.prototype.P2 = ‘P2’;

   var cf1 = new CF,
       cf2 = new CF,
       cf3 = new CF,
       cf4 = new CF,
       cf5 = new CF;
Alipay Inc


                   Simple Object
    function User(){
      this.firstName = ‘颂’;
      this.lastName = ‘赞’;
    }
    var user = {firstName:’zhu’,lastName:’qi’};
    User.prototype = user;
    var userByConstructor = new User();

  user                                       userByConstructor
  firstName zhu                              firstName   颂
  lastName qi                                lastName    赞
              prototypeObject? [Object]                  prototypeObject:user
  prototype                                  prototype
              constructor:Object                         constructor:Function
Alipay Inc

   function User(){
     this.sex= ‘male’;
   }
   User.prototype = {
     getSex : function (){return this.sex;}
   };
   function AlipayUser(){
     this.sex = ‘female’;
   }
   function TaobaoUser(){}

   AlipayUser.prototype = new User;
   TaobaoUser.prototype = new User;

   AlipayUser.prototype.constructor = AlipayUser;
   TaobaoUser.prototype.constructor = TaobaoUser;

   var alipay_user = new AlipayUser ();
   var taobao_user = new TaobaoUser;
Alipay Inc


 User
 sex          male

              prototypeObject: Object
 prototype
              constructor:Function      TaobaoUser
                                        sex         male

                                                    prototypeObject: Object
 AlipayUser
                                        prototype
 sex          female                                constructor:TaobaoUser
              prototypeObject: Object
 prototype
              constructor:AlipayUser
Alipay Inc



    console.log(alipay_user .constructor);//AlipayUser

    console.log(taobao_user .constructor);//TaobaoUser

    console.log(alipay_user instanceof AlipayUser );//true;

    console.log(taobao_user instanceof TaobaoUser);//true;

    console.log(
      taobao_user instanceof User
      &&
      alipay_user instanceof User
    );//true
Alipay Inc

  Defining and Calling method in Class
    function TaobaoUser(cfg){
      User.call(this,cfg);
      this.sex = ‘undefined’;
      this.instances = this.instances || [];
      this.instances.push(this);
    }
    TaobaoUser.getAllInstances = function (){
      return this.instances;
    };
    TaobaoUser.prototype = new User;
    TaobaoUser.prototype.setSex = function (sex){
      this.sex = sex;
      return this;
    };
    TaobaoUser.prototype.constructor = TaobaoUser;

    var user = new TaobaoUser();
    user.setSex(‘female’).getSex();//female;
Alipay Inc

Calling method of SuperClass from SubClass

   User._getSelfSex_ = function (){
     return this.sex || ‘This is User’s sex.’;
   };

   TaobaoUser.getSex = function (){
     var superSex = User.prototype.getSex();
     return User._getSelfSex_() + ‘ ’ + this.sex;
   };

   var user = new TaobaoUser;
   user.getSex(); // This is User’s sex undefined;
Alipay Inc

  Object Oriented Programming Goals

   • Encapsulation
     实现类成员,方法的调用


   • Polymorphism
     实现在不同的类或对象中响应同样的方法或事件


   • Inheritance
     根据一个对象或类的行为来定义另一个对象或类的行为
Alipay Inc

More Related Content

What's hot

Paying off technical debt with PHPSpec
Paying off technical debt with PHPSpecPaying off technical debt with PHPSpec
Paying off technical debt with PHPSpec
Lewis Wright
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
Donald Sipe
 
Crafting Quality PHP Applications (ConFoo YVR 2017)
Crafting Quality PHP Applications (ConFoo YVR 2017)Crafting Quality PHP Applications (ConFoo YVR 2017)
Crafting Quality PHP Applications (ConFoo YVR 2017)
James Titcumb
 
Java ap is you should know
Java ap is you should knowJava ap is you should know
Java ap is you should know
Hendrik Ebbers
 
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
James Titcumb
 
IoC&Laravel
IoC&LaravelIoC&Laravel
IoC&Laravel
Hoang Long
 
Patterns In-Javascript
Patterns In-JavascriptPatterns In-Javascript
Patterns In-Javascript
Mindfire Solutions
 
Web application
Web applicationWeb application
Web application
aquarius070287
 
Web application
Web applicationWeb application
Web application
Om Vikram Thapa
 
Moneyandcurrency2
Moneyandcurrency2Moneyandcurrency2
Moneyandcurrency2
Pavel Rozenblioum
 
An Introduction to Ruby on Rails 20100506
An Introduction to Ruby on Rails 20100506An Introduction to Ruby on Rails 20100506
An Introduction to Ruby on Rails 20100506
Vu Hung Nguyen
 
Beyond MVC: from Model to Domain
Beyond MVC: from Model to DomainBeyond MVC: from Model to Domain
Beyond MVC: from Model to Domain
Jeremy Cook
 
An introduction-to-ruby-on-rails
An introduction-to-ruby-on-railsAn introduction-to-ruby-on-rails
An introduction-to-ruby-on-rails
vinicorp
 
ParisJS #10 : RequireJS
ParisJS #10 : RequireJSParisJS #10 : RequireJS
ParisJS #10 : RequireJS
Julien Cabanès
 
Testing untestable Code - PFCongres 2010
Testing untestable Code - PFCongres 2010Testing untestable Code - PFCongres 2010
Testing untestable Code - PFCongres 2010
Stephan Hochdörfer
 
BDD style Unit Testing
BDD style Unit TestingBDD style Unit Testing
BDD style Unit Testing
Wen-Tien Chang
 
SIL for the first time
SIL for the first timeSIL for the first time
SIL for the first time
Yusuke Kita
 
Advance JS and oop
Advance JS and oopAdvance JS and oop
Advance JS and oop
Abuzer Firdousi
 
Best practices for crafting high quality PHP apps (PHP South Africa 2018)
Best practices for crafting high quality PHP apps (PHP South Africa 2018)Best practices for crafting high quality PHP apps (PHP South Africa 2018)
Best practices for crafting high quality PHP apps (PHP South Africa 2018)
James Titcumb
 
slingmodels
slingmodelsslingmodels
slingmodels
Ankur Chauhan
 

What's hot (20)

Paying off technical debt with PHPSpec
Paying off technical debt with PHPSpecPaying off technical debt with PHPSpec
Paying off technical debt with PHPSpec
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
Crafting Quality PHP Applications (ConFoo YVR 2017)
Crafting Quality PHP Applications (ConFoo YVR 2017)Crafting Quality PHP Applications (ConFoo YVR 2017)
Crafting Quality PHP Applications (ConFoo YVR 2017)
 
Java ap is you should know
Java ap is you should knowJava ap is you should know
Java ap is you should know
 
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
 
IoC&Laravel
IoC&LaravelIoC&Laravel
IoC&Laravel
 
Patterns In-Javascript
Patterns In-JavascriptPatterns In-Javascript
Patterns In-Javascript
 
Web application
Web applicationWeb application
Web application
 
Web application
Web applicationWeb application
Web application
 
Moneyandcurrency2
Moneyandcurrency2Moneyandcurrency2
Moneyandcurrency2
 
An Introduction to Ruby on Rails 20100506
An Introduction to Ruby on Rails 20100506An Introduction to Ruby on Rails 20100506
An Introduction to Ruby on Rails 20100506
 
Beyond MVC: from Model to Domain
Beyond MVC: from Model to DomainBeyond MVC: from Model to Domain
Beyond MVC: from Model to Domain
 
An introduction-to-ruby-on-rails
An introduction-to-ruby-on-railsAn introduction-to-ruby-on-rails
An introduction-to-ruby-on-rails
 
ParisJS #10 : RequireJS
ParisJS #10 : RequireJSParisJS #10 : RequireJS
ParisJS #10 : RequireJS
 
Testing untestable Code - PFCongres 2010
Testing untestable Code - PFCongres 2010Testing untestable Code - PFCongres 2010
Testing untestable Code - PFCongres 2010
 
BDD style Unit Testing
BDD style Unit TestingBDD style Unit Testing
BDD style Unit Testing
 
SIL for the first time
SIL for the first timeSIL for the first time
SIL for the first time
 
Advance JS and oop
Advance JS and oopAdvance JS and oop
Advance JS and oop
 
Best practices for crafting high quality PHP apps (PHP South Africa 2018)
Best practices for crafting high quality PHP apps (PHP South Africa 2018)Best practices for crafting high quality PHP apps (PHP South Africa 2018)
Best practices for crafting high quality PHP apps (PHP South Africa 2018)
 
slingmodels
slingmodelsslingmodels
slingmodels
 

Viewers also liked

SASS 让你更爽的 编写CSS
SASS 让你更爽的 编写CSS SASS 让你更爽的 编写CSS
SASS 让你更爽的 编写CSS
Zhu Qi
 
用户体验组设计流程
用户体验组设计流程用户体验组设计流程
用户体验组设计流程Zhu Qi
 
Web app share
Web app shareWeb app share
Web app share
Zhu Qi
 
支付宝WAP站点收银台适配ios &android
支付宝WAP站点收银台适配ios &android支付宝WAP站点收银台适配ios &android
支付宝WAP站点收银台适配ios &android
Zhu Qi
 
The core of javascript
The core of javascriptThe core of javascript
The core of javascript
springuper
 
Building User-Centred Websites with Drupal
Building User-Centred Websites with DrupalBuilding User-Centred Websites with Drupal
Building User-Centred Websites with Drupal
amanda etches
 
Sharing Those Resources - It\'s All About Access and Integration
Sharing Those Resources - It\'s All About Access and IntegrationSharing Those Resources - It\'s All About Access and Integration
Sharing Those Resources - It\'s All About Access and Integration
Martha Rossi
 
Reference on the Go: Text Messaging and More
Reference on the Go: Text Messaging and MoreReference on the Go: Text Messaging and More
Reference on the Go: Text Messaging and More
Ellen Peterson
 
How I Built a Website for $16 in Chocolate
How I Built a Website for $16 in ChocolateHow I Built a Website for $16 in Chocolate
How I Built a Website for $16 in Chocolate
Laura Crossett
 
Dallas Drupal Days 2012 - Introduction to less sass-compass
Dallas Drupal Days 2012  - Introduction to less sass-compassDallas Drupal Days 2012  - Introduction to less sass-compass
Dallas Drupal Days 2012 - Introduction to less sass-compass
Chris Lee
 
Assessing Information Literacy Online
Assessing Information Literacy OnlineAssessing Information Literacy Online
Assessing Information Literacy Online
Margot
 

Viewers also liked (11)

SASS 让你更爽的 编写CSS
SASS 让你更爽的 编写CSS SASS 让你更爽的 编写CSS
SASS 让你更爽的 编写CSS
 
用户体验组设计流程
用户体验组设计流程用户体验组设计流程
用户体验组设计流程
 
Web app share
Web app shareWeb app share
Web app share
 
支付宝WAP站点收银台适配ios &android
支付宝WAP站点收银台适配ios &android支付宝WAP站点收银台适配ios &android
支付宝WAP站点收银台适配ios &android
 
The core of javascript
The core of javascriptThe core of javascript
The core of javascript
 
Building User-Centred Websites with Drupal
Building User-Centred Websites with DrupalBuilding User-Centred Websites with Drupal
Building User-Centred Websites with Drupal
 
Sharing Those Resources - It\'s All About Access and Integration
Sharing Those Resources - It\'s All About Access and IntegrationSharing Those Resources - It\'s All About Access and Integration
Sharing Those Resources - It\'s All About Access and Integration
 
Reference on the Go: Text Messaging and More
Reference on the Go: Text Messaging and MoreReference on the Go: Text Messaging and More
Reference on the Go: Text Messaging and More
 
How I Built a Website for $16 in Chocolate
How I Built a Website for $16 in ChocolateHow I Built a Website for $16 in Chocolate
How I Built a Website for $16 in Chocolate
 
Dallas Drupal Days 2012 - Introduction to less sass-compass
Dallas Drupal Days 2012  - Introduction to less sass-compassDallas Drupal Days 2012  - Introduction to less sass-compass
Dallas Drupal Days 2012 - Introduction to less sass-compass
 
Assessing Information Literacy Online
Assessing Information Literacy OnlineAssessing Information Literacy Online
Assessing Information Literacy Online
 

Similar to Understand prototype

Object Oriented Programming In JavaScript
Object Oriented Programming In JavaScriptObject Oriented Programming In JavaScript
Object Oriented Programming In JavaScript
Forziatech
 
JavaScript Interview Questions Part - 1.pdf
JavaScript Interview Questions Part - 1.pdfJavaScript Interview Questions Part - 1.pdf
JavaScript Interview Questions Part - 1.pdf
katarichallenge
 
Metaprogramming in ES6
Metaprogramming in ES6Metaprogramming in ES6
Metaprogramming in ES6
Héctor Pablos López
 
Javascript Styles and some tips
Javascript Styles and some tipsJavascript Styles and some tips
Javascript Styles and some tips
Vítor Baptista
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
Mike Subelsky
 
Core concepts-javascript
Core concepts-javascriptCore concepts-javascript
Core concepts-javascript
Prajwala Manchikatla
 
Javascript Everywhere
Javascript EverywhereJavascript Everywhere
Javascript Everywhere
Pascal Rettig
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
Subramanyan Murali
 
JavaScript In Object Oriented Way
JavaScript In Object Oriented WayJavaScript In Object Oriented Way
JavaScript In Object Oriented Way
Borey Lim
 
Functional Javascript
Functional JavascriptFunctional Javascript
Functional Javascript
guest4d57e6
 
Node Architecture and Getting Started with Express
Node Architecture and Getting Started with ExpressNode Architecture and Getting Started with Express
Node Architecture and Getting Started with Express
jguerrero999
 
JavaScript For CSharp Developer
JavaScript For CSharp DeveloperJavaScript For CSharp Developer
JavaScript For CSharp Developer
Sarvesh Kushwaha
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
Fwdays
 
What's new in PHP 8.0?
What's new in PHP 8.0?What's new in PHP 8.0?
What's new in PHP 8.0?
Nikita Popov
 
CiviCRM API v3
CiviCRM API v3CiviCRM API v3
CiviCRM API v3
Xavier dutoit
 
Javascript for the c# developer
Javascript for the c# developerJavascript for the c# developer
Javascript for the c# developer
Salvatore Fazio
 
Spring data requery
Spring data requerySpring data requery
Spring data requery
Sunghyouk Bae
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
Yakov Fain
 
JavaScript Essentials
JavaScript EssentialsJavaScript Essentials
JavaScript Essentials
Triphon Statkov
 
Intro to computer vision in .net update
Intro to computer vision in .net   updateIntro to computer vision in .net   update
Intro to computer vision in .net update
Stephen Lorello
 

Similar to Understand prototype (20)

Object Oriented Programming In JavaScript
Object Oriented Programming In JavaScriptObject Oriented Programming In JavaScript
Object Oriented Programming In JavaScript
 
JavaScript Interview Questions Part - 1.pdf
JavaScript Interview Questions Part - 1.pdfJavaScript Interview Questions Part - 1.pdf
JavaScript Interview Questions Part - 1.pdf
 
Metaprogramming in ES6
Metaprogramming in ES6Metaprogramming in ES6
Metaprogramming in ES6
 
Javascript Styles and some tips
Javascript Styles and some tipsJavascript Styles and some tips
Javascript Styles and some tips
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
 
Core concepts-javascript
Core concepts-javascriptCore concepts-javascript
Core concepts-javascript
 
Javascript Everywhere
Javascript EverywhereJavascript Everywhere
Javascript Everywhere
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
JavaScript In Object Oriented Way
JavaScript In Object Oriented WayJavaScript In Object Oriented Way
JavaScript In Object Oriented Way
 
Functional Javascript
Functional JavascriptFunctional Javascript
Functional Javascript
 
Node Architecture and Getting Started with Express
Node Architecture and Getting Started with ExpressNode Architecture and Getting Started with Express
Node Architecture and Getting Started with Express
 
JavaScript For CSharp Developer
JavaScript For CSharp DeveloperJavaScript For CSharp Developer
JavaScript For CSharp Developer
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
 
What's new in PHP 8.0?
What's new in PHP 8.0?What's new in PHP 8.0?
What's new in PHP 8.0?
 
CiviCRM API v3
CiviCRM API v3CiviCRM API v3
CiviCRM API v3
 
Javascript for the c# developer
Javascript for the c# developerJavascript for the c# developer
Javascript for the c# developer
 
Spring data requery
Spring data requerySpring data requery
Spring data requery
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
JavaScript Essentials
JavaScript EssentialsJavaScript Essentials
JavaScript Essentials
 
Intro to computer vision in .net update
Intro to computer vision in .net   updateIntro to computer vision in .net   update
Intro to computer vision in .net update
 

Recently uploaded

Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdfAI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
Techgropse Pvt.Ltd.
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Things to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUUThings to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUU
FODUU
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 

Recently uploaded (20)

Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdfAI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Things to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUUThings to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUU
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 

Understand prototype

  • 1. Alipay Inc Understand Prototype 颂赞 (http://qiqicartoon.com)
  • 2. Alipay Inc • What is prototype? • How to inherit? • Simple Object • Defining a Class • Defining and Calling method in Class • Calling the SuperClass from SubClass • Overriding Method of SuperClass in SubClass • Calling Method of SuperClass from SubClass
  • 3. Alipay Inc What is prototype? By ECMASCRIPT: Each constructor is a function that has a property named ―prototype that is used to implement prototype-based inheritance and shared properties.
  • 4. Alipay Inc Prototype is prototype? Prototype contain: • Prototype property • Prototype object
  • 5. Alipay Inc What is prototype? function User(){ //… } Prototype property User.prototype = { //methods… }; Prototype object
  • 6. Alipay Inc What is prototype? Prototype object也是类成员的集合
  • 7. Alipay Inc What is prototype? Array, Object, Number, Function, Null, Undefind function _arrayObj(){} Array.prototype = new _arrayObj(); console.log(Array.prototype.constructor) ;//Array,not Function var userName = ‘zhuiq’, companies = [‘alipay’,’alisoft’], friends = { ‘a’:{},’b’:{} }; userName.prototype = {};//? companies.prototype = {};//? friends.prototype = {};//? null.prototype //? undefined.prototype //?
  • 8. Alipay Inc What is prototype? Javascript原始对象的prototype是只读的! 只有函数对象才有prototype属性!
  • 9. Alipay Inc What is prototype? methods • __defineGetter__ • __defineSetter__ • eval • hasOwnProperty • isPrototypeOf • valueOf Prototype • watch Object • unwatch • toString properties • toSource • propertyIsEnumerable • constructor • __noSuchMethod__ • __parent__ • __lookupGetter__ • __proto__ • __lookupSetter__ • __count__
  • 10. Alipay Inc How to inherit? PHP: extends JAVA: extends Ruby: < ASP: : Python: class subClassName(SuperClassName) C++: : Javascript: prototype
  • 11. Alipay Inc How to inherit?
  • 12. Alipay Inc How to inherit? var CF= function (){}, CFp = {CFP1:1,CFP2:2}; CF.prototype = CFp; CF.prototype.P1 = ‘P1’; CF.prototype.P2 = ‘P2’; var cf1 = new CF, cf2 = new CF, cf3 = new CF, cf4 = new CF, cf5 = new CF;
  • 13. Alipay Inc Simple Object function User(){ this.firstName = ‘颂’; this.lastName = ‘赞’; } var user = {firstName:’zhu’,lastName:’qi’}; User.prototype = user; var userByConstructor = new User(); user userByConstructor firstName zhu firstName 颂 lastName qi lastName 赞 prototypeObject? [Object] prototypeObject:user prototype prototype constructor:Object constructor:Function
  • 14. Alipay Inc function User(){ this.sex= ‘male’; } User.prototype = { getSex : function (){return this.sex;} }; function AlipayUser(){ this.sex = ‘female’; } function TaobaoUser(){} AlipayUser.prototype = new User; TaobaoUser.prototype = new User; AlipayUser.prototype.constructor = AlipayUser; TaobaoUser.prototype.constructor = TaobaoUser; var alipay_user = new AlipayUser (); var taobao_user = new TaobaoUser;
  • 15. Alipay Inc User sex male prototypeObject: Object prototype constructor:Function TaobaoUser sex male prototypeObject: Object AlipayUser prototype sex female constructor:TaobaoUser prototypeObject: Object prototype constructor:AlipayUser
  • 16. Alipay Inc console.log(alipay_user .constructor);//AlipayUser console.log(taobao_user .constructor);//TaobaoUser console.log(alipay_user instanceof AlipayUser );//true; console.log(taobao_user instanceof TaobaoUser);//true; console.log( taobao_user instanceof User && alipay_user instanceof User );//true
  • 17. Alipay Inc Defining and Calling method in Class function TaobaoUser(cfg){ User.call(this,cfg); this.sex = ‘undefined’; this.instances = this.instances || []; this.instances.push(this); } TaobaoUser.getAllInstances = function (){ return this.instances; }; TaobaoUser.prototype = new User; TaobaoUser.prototype.setSex = function (sex){ this.sex = sex; return this; }; TaobaoUser.prototype.constructor = TaobaoUser; var user = new TaobaoUser(); user.setSex(‘female’).getSex();//female;
  • 18. Alipay Inc Calling method of SuperClass from SubClass User._getSelfSex_ = function (){ return this.sex || ‘This is User’s sex.’; }; TaobaoUser.getSex = function (){ var superSex = User.prototype.getSex(); return User._getSelfSex_() + ‘ ’ + this.sex; }; var user = new TaobaoUser; user.getSex(); // This is User’s sex undefined;
  • 19. Alipay Inc Object Oriented Programming Goals • Encapsulation 实现类成员,方法的调用 • Polymorphism 实现在不同的类或对象中响应同样的方法或事件 • Inheritance 根据一个对象或类的行为来定义另一个对象或类的行为