SlideShare a Scribd company logo
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 );

More Related Content

PPTX
Introduction to Javascript
KEY
Javascript3
PDF
삼성 바다 앱개발 실패 노하우 2부
PDF
JavaScript: enter the dragon
PPTX
Fundamentals of computer programming by Dr. A. Charan Kumari
PDF
Demystifying Prototypes
PDF
Java8: Language Enhancements
Introduction to Javascript
Javascript3
삼성 바다 앱개발 실패 노하우 2부
JavaScript: enter the dragon
Fundamentals of computer programming by Dr. A. Charan Kumari
Demystifying Prototypes
Java8: Language Enhancements

What's hot (20)

PPTX
Php-Continuation
DOCX
Check the output of the following code then recode it to eliminate fu
TXT
manager
PDF
Functions
PDF
Aftermath of functional programming. The good parts
PPTX
Aftermath of functional programming. the good parts
PDF
Swift で JavaScript 始めませんか? #iOSDC
PDF
How to practice functional programming in react
PDF
TDD - Test Driven Development in Swift (iOS) with Cuckoo, Quick and Nimble
PPTX
Test in action week 2
PPTX
Javascript this keyword
PPTX
Functions
PDF
Scala is java8.next()
DOC
Reverse123
PDF
Reactive programming
ODP
ekb.py - Python VS ...
PDF
Java Script Workshop
PDF
Grammatical Optimization
PPSX
C programming function
PDF
Writing beautiful code with Java 8
Php-Continuation
Check the output of the following code then recode it to eliminate fu
manager
Functions
Aftermath of functional programming. The good parts
Aftermath of functional programming. the good parts
Swift で JavaScript 始めませんか? #iOSDC
How to practice functional programming in react
TDD - Test Driven Development in Swift (iOS) with Cuckoo, Quick and Nimble
Test in action week 2
Javascript this keyword
Functions
Scala is java8.next()
Reverse123
Reactive programming
ekb.py - Python VS ...
Java Script Workshop
Grammatical Optimization
C programming function
Writing beautiful code with Java 8
Ad

Similar to javascript prototype (20)

PDF
FITC CoffeeScript 101
PDF
The many facets of code reuse in JavaScript
PDF
JS Level Up: Prototypes
PDF
JavaScript Survival Guide
KEY
Coffee Scriptでenchant.js
PPT
Advanced JavaScript
PDF
運用Closure Compiler 打造高品質的JavaScript
KEY
Inheritance patterns
KEY
みゆっき☆Think#7 「本気で学ぶJavascript」
KEY
第7回みゆっき☆Think 本気で学ぶ JavaScript
PDF
Prototype
PDF
JavaScript Primer
PDF
JavaScript Inheritance
PDF
Say It With Javascript
PDF
Week 06 Modular Javascript_Brandon, S. H. Wu
PPTX
Object Oriented JavaScript
PPTX
Typescript barcelona
PPT
Advanced Javascript
PPT
Advanced Javascript
PPT
Advanced Javascript
FITC CoffeeScript 101
The many facets of code reuse in JavaScript
JS Level Up: Prototypes
JavaScript Survival Guide
Coffee Scriptでenchant.js
Advanced JavaScript
運用Closure Compiler 打造高品質的JavaScript
Inheritance patterns
みゆっき☆Think#7 「本気で学ぶJavascript」
第7回みゆっき☆Think 本気で学ぶ JavaScript
Prototype
JavaScript Primer
JavaScript Inheritance
Say It With Javascript
Week 06 Modular Javascript_Brandon, S. H. Wu
Object Oriented JavaScript
Typescript barcelona
Advanced Javascript
Advanced Javascript
Advanced Javascript
Ad

Recently uploaded (20)

PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Getting Started with Data Integration: FME Form 101
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Web App vs Mobile App What Should You Build First.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
Tartificialntelligence_presentation.pptx
PPTX
A Presentation on Touch Screen Technology
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
August Patch Tuesday
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PPTX
Chapter 5: Probability Theory and Statistics
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Getting Started with Data Integration: FME Form 101
Unlocking AI with Model Context Protocol (MCP)
Web App vs Mobile App What Should You Build First.pdf
Programs and apps: productivity, graphics, security and other tools
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
A comparative analysis of optical character recognition models for extracting...
Encapsulation_ Review paper, used for researhc scholars
Heart disease approach using modified random forest and particle swarm optimi...
WOOl fibre morphology and structure.pdf for textiles
NewMind AI Weekly Chronicles - August'25-Week II
Tartificialntelligence_presentation.pptx
A Presentation on Touch Screen Technology
MIND Revenue Release Quarter 2 2025 Press Release
August Patch Tuesday
A novel scalable deep ensemble learning framework for big data classification...
Univ-Connecticut-ChatGPT-Presentaion.pdf
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Chapter 5: Probability Theory and Statistics
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf

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