SlideShare ist ein Scribd-Unternehmen logo
1 von 7
S53

#2
2-1 type
2-2 prototype
2-3 prototype chain
2-4 technique

2012.10.24 20:30 ~ 22:30
Type = Id = Category = Group                var a = {type:1};
int   memory▼ recognize▼ scalable●          var b = {type:2};

                                            var a = {type:"food"};
String       memory▲ recognize▲ scalable▼
                                            var b = {type:"tool"};
Object       memory▼ recognize▲ scalable▲   var food = {};
                                            var tool = {};
Self(Recusive) - Reference                  var a = {type:food};
var food = {};                              var b = {type:tool};
var tool = {};
alert( food.type );

Conclusion = Function
var food = function(){};
var tool = function(){};
var a = {type:food};
var b = {type:tool};
alert( a.type ); // food
alert( food.type ); // undefined
function test(){                                Function['test'] = {
    ...                                             ...
}                                                   prototype:{
alert( typeof test.prototype );
                                                        constructor:Function['test']
alert( test === test.prototype.constructor );       }
                                                };

var a = new test( 3 );                          var a = {
                                                     __proto__:test.prototype
alert( a.constructor === test );                };
alert( a instanceof test );
                                                a = test.call( a, 3 ) || a;
function test( $val ){                          a={
    this.val = $val;                                  __proto__:test.prototype,
}
                                                      val:3
                                                };

function test( $val ){                          a = {};
    this.val = $val;
    return {};
}
function test1(){                                 var a = new test1;
}
function test2(){                                 alert( a.constructor === test1 );
}                                                 alert( a instanceof test1 );

test1.prototype.constructor = test2;
alert( test2 === test1.prototype.constructor );

test1.prototype = test2.prototype;                function test(){
alert( test2 === test1.prototype.constructor );   }
                                                  test.prototype.val = 3;
function test(){
}                                                 var a = new test, b = new test;
test.prototype.action = function(){};
                                                  alert( a.val );
var a = new test, b = new test;
                                                  a.val = 5;
alert( a.action === b.action );                   alert( b.val );
function parent(){                                       a={
}                                                           __proto__:child.prototype
parent.prototype.add = function(){};                     };

function child(){                                        //1. a[???]
}                                                        //2. a.__proto__[???]
child.prototype.action = function(){};
                                                         a.add === undefined
var a = new child;
a.add();

Goal = a.__proto__.__proto__.add();

1. a.__proto__ = child.prototype;

2. a.__proto__.__proto__ = child.prototype.__proto__ = parent.prototype;

3. child.prototype = new parent;

4. a.__proto__.__proto__.add = parent.prototype.add;
function parent(){
}
parent.prototype.add = function(){};
parent.prototype.remove = function(){};
...

function child( a, b ){
     this.a = a;
     this.b = b;
}
child.prototype = new parent;
child.prototype.action1 = function(){};
child.prototype.action2 = function(){};
...

var a = new child;
a.a; // a.a
a.b; // a.b
a.action1(); // a.__proto__.action1
a.action2(); // a.__proto__.action2
a.add();        // a.__proto__.__proto__.add
a.remove(); // a.__proto__.__proto__.remove
function test( a, b ){                      function test( a, b ){
    if( this == window ){                       ...
          return new test( a, b );          }
    }else{
          this.a = a;                       test.prototype.action1 = function(){};
          this.b = b;                       test.prototype.action2 = function(){};
    }
}                                           test.prototype = {
                                                 constructor: test.prototype.constructor,
var a = test( 3, 5 );                            action1: function(){},
var b = new test( 3, 5 );                        action2: function(){}
                                            };
alert( a.constructor === b.constructor );

function parent( a ){
     this.a = a;
}
function child( a, b ){
     this.super( a );
     this.b = b;
}
child.prototype = new parent;
child.prototype.super = parent;

var a = new child( 3, 6 );

alert( a.a );

Weitere ähnliche Inhalte

Was ist angesagt?

Php-Continuation
Php-ContinuationPhp-Continuation
Php-Continuation
lotlot
 
Test in action week 2
Test in action   week 2Test in action   week 2
Test in action week 2
Yi-Huan Chan
 

Was ist angesagt? (20)

Php-Continuation
Php-ContinuationPhp-Continuation
Php-Continuation
 
Check the output of the following code then recode it to eliminate fu
 Check the output of the following code then recode it to eliminate fu Check the output of the following code then recode it to eliminate fu
Check the output of the following code then recode it to eliminate fu
 
manager
managermanager
manager
 
Functions
FunctionsFunctions
Functions
 
Aftermath of functional programming. The good parts
Aftermath of functional programming. The good partsAftermath of functional programming. The good parts
Aftermath of functional programming. The good parts
 
Aftermath of functional programming. the good parts
Aftermath of functional programming. the good partsAftermath of functional programming. the good parts
Aftermath of functional programming. the good parts
 
Swift で JavaScript 始めませんか? #iOSDC
Swift で JavaScript 始めませんか? #iOSDCSwift で JavaScript 始めませんか? #iOSDC
Swift で JavaScript 始めませんか? #iOSDC
 
How to practice functional programming in react
How to practice functional programming in reactHow to practice functional programming in react
How to practice functional programming in react
 
TDD - Test Driven Development in Swift (iOS) with Cuckoo, Quick and Nimble
TDD - Test Driven Development in Swift (iOS) with Cuckoo, Quick and NimbleTDD - Test Driven Development in Swift (iOS) with Cuckoo, Quick and Nimble
TDD - Test Driven Development in Swift (iOS) with Cuckoo, Quick and Nimble
 
Test in action week 2
Test in action   week 2Test in action   week 2
Test in action week 2
 
Javascript this keyword
Javascript this keywordJavascript this keyword
Javascript this keyword
 
Functions
FunctionsFunctions
Functions
 
Scala is java8.next()
Scala is java8.next()Scala is java8.next()
Scala is java8.next()
 
Reverse123
Reverse123Reverse123
Reverse123
 
Reactive programming
Reactive programmingReactive programming
Reactive programming
 
ekb.py - Python VS ...
ekb.py - Python VS ...ekb.py - Python VS ...
ekb.py - Python VS ...
 
Java Script Workshop
Java Script WorkshopJava Script Workshop
Java Script Workshop
 
Grammatical Optimization
Grammatical OptimizationGrammatical Optimization
Grammatical Optimization
 
C programming function
C  programming functionC  programming function
C programming function
 
Writing beautiful code with Java 8
Writing beautiful code with Java 8Writing beautiful code with Java 8
Writing beautiful code with Java 8
 

Ähnlich wie javascript prototype

Unit testing with PHPUnit
Unit testing with PHPUnitUnit testing with PHPUnit
Unit testing with PHPUnit
ferca_sl
 
OO JS for AS3 Devs
OO JS for AS3 DevsOO JS for AS3 Devs
OO JS for AS3 Devs
Jason Hanson
 
Java script object model
Java script object modelJava script object model
Java script object model
James Hsieh
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
whitneyleman54422
 
LinkedIn TBC JavaScript 100: Functions
 LinkedIn TBC JavaScript 100: Functions LinkedIn TBC JavaScript 100: Functions
LinkedIn TBC JavaScript 100: Functions
Adam Crabtree
 

Ähnlich wie javascript prototype (20)

Understanding JavaScript Testing
Understanding JavaScript TestingUnderstanding JavaScript Testing
Understanding JavaScript Testing
 
Unit testing with PHPUnit
Unit testing with PHPUnitUnit testing with PHPUnit
Unit testing with PHPUnit
 
Testing, Performance Analysis, and jQuery 1.4
Testing, Performance Analysis, and jQuery 1.4Testing, Performance Analysis, and jQuery 1.4
Testing, Performance Analysis, and jQuery 1.4
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
Unittesting JavaScript with Evidence
Unittesting JavaScript with EvidenceUnittesting JavaScript with Evidence
Unittesting JavaScript with Evidence
 
4front en
4front en4front en
4front en
 
Javascript
JavascriptJavascript
Javascript
 
OO JS for AS3 Devs
OO JS for AS3 DevsOO JS for AS3 Devs
OO JS for AS3 Devs
 
Ian 20150116 java script oop
Ian 20150116 java script oopIan 20150116 java script oop
Ian 20150116 java script oop
 
Say It With Javascript
Say It With JavascriptSay It With Javascript
Say It With Javascript
 
Method overloading, recursion, passing and returning objects from method, new...
Method overloading, recursion, passing and returning objects from method, new...Method overloading, recursion, passing and returning objects from method, new...
Method overloading, recursion, passing and returning objects from method, new...
 
JavaScript Classes and Inheritance
JavaScript Classes and InheritanceJavaScript Classes and Inheritance
JavaScript Classes and Inheritance
 
04 Advanced Javascript
04 Advanced Javascript04 Advanced Javascript
04 Advanced Javascript
 
25-functions.ppt
25-functions.ppt25-functions.ppt
25-functions.ppt
 
Js objects
Js objectsJs objects
Js objects
 
Deploying Straight to Production
Deploying Straight to ProductionDeploying Straight to Production
Deploying Straight to Production
 
Java script object model
Java script object modelJava script object model
Java script object model
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
 
Powerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best PracticesPowerful JavaScript Tips and Best Practices
Powerful JavaScript Tips and Best Practices
 
LinkedIn TBC JavaScript 100: Functions
 LinkedIn TBC JavaScript 100: Functions LinkedIn TBC JavaScript 100: Functions
LinkedIn TBC JavaScript 100: Functions
 

Kürzlich hochgeladen

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Kürzlich hochgeladen (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

javascript prototype

  • 1. S53 #2 2-1 type 2-2 prototype 2-3 prototype chain 2-4 technique 2012.10.24 20:30 ~ 22:30
  • 2. Type = Id = Category = Group var a = {type:1}; int memory▼ recognize▼ scalable● var b = {type:2}; var a = {type:"food"}; String memory▲ recognize▲ scalable▼ var b = {type:"tool"}; Object memory▼ recognize▲ scalable▲ var food = {}; var tool = {}; Self(Recusive) - Reference var a = {type:food}; var food = {}; var b = {type:tool}; var tool = {}; alert( food.type ); Conclusion = Function var food = function(){}; var tool = function(){}; var a = {type:food}; var b = {type:tool}; alert( a.type ); // food alert( food.type ); // undefined
  • 3. function test(){ Function['test'] = { ... ... } prototype:{ alert( typeof test.prototype ); constructor:Function['test'] alert( test === test.prototype.constructor ); } }; var a = new test( 3 ); var a = { __proto__:test.prototype alert( a.constructor === test ); }; alert( a instanceof test ); a = test.call( a, 3 ) || a; function test( $val ){ a={ this.val = $val; __proto__:test.prototype, } val:3 }; function test( $val ){ a = {}; this.val = $val; return {}; }
  • 4. function test1(){ var a = new test1; } function test2(){ alert( a.constructor === test1 ); } alert( a instanceof test1 ); test1.prototype.constructor = test2; alert( test2 === test1.prototype.constructor ); test1.prototype = test2.prototype; function test(){ alert( test2 === test1.prototype.constructor ); } test.prototype.val = 3; function test(){ } var a = new test, b = new test; test.prototype.action = function(){}; alert( a.val ); var a = new test, b = new test; a.val = 5; alert( a.action === b.action ); alert( b.val );
  • 5. function parent(){ a={ } __proto__:child.prototype parent.prototype.add = function(){}; }; function child(){ //1. a[???] } //2. a.__proto__[???] child.prototype.action = function(){}; a.add === undefined var a = new child; a.add(); Goal = a.__proto__.__proto__.add(); 1. a.__proto__ = child.prototype; 2. a.__proto__.__proto__ = child.prototype.__proto__ = parent.prototype; 3. child.prototype = new parent; 4. a.__proto__.__proto__.add = parent.prototype.add;
  • 6. function parent(){ } parent.prototype.add = function(){}; parent.prototype.remove = function(){}; ... function child( a, b ){ this.a = a; this.b = b; } child.prototype = new parent; child.prototype.action1 = function(){}; child.prototype.action2 = function(){}; ... var a = new child; a.a; // a.a a.b; // a.b a.action1(); // a.__proto__.action1 a.action2(); // a.__proto__.action2 a.add(); // a.__proto__.__proto__.add a.remove(); // a.__proto__.__proto__.remove
  • 7. function test( a, b ){ function test( a, b ){ if( this == window ){ ... return new test( a, b ); } }else{ this.a = a; test.prototype.action1 = function(){}; this.b = b; test.prototype.action2 = function(){}; } } test.prototype = { constructor: test.prototype.constructor, var a = test( 3, 5 ); action1: function(){}, var b = new test( 3, 5 ); action2: function(){} }; alert( a.constructor === b.constructor ); function parent( a ){ this.a = a; } function child( a, b ){ this.super( a ); this.b = b; } child.prototype = new parent; child.prototype.super = parent; var a = new child( 3, 6 ); alert( a.a );