SlideShare a Scribd company logo
1 of 25
Javascript - Core
object
• Javascript                    (   int)
         object

• function        object

• object拥         组properties              为
  null    prototype
object

• 义 var foo = { x:10, y: 20 };
• 读 foo.x OR foo[‘x’]
• 设 foo.x = 123 OR foo[‘x’] = 123
•          动态获 时
object

•   prototype          object


•     过__proto__        prototype


•   foo.__proto__ OR
    foo[‘__proto__’]
prototype chain
•            object 过__proto__
        实现继              property

• property    查   规则

 •            __proto__为null为

 •            property
prototype chain
•   var a = { x: 10,
       calculate: function(z) {
           return this.x + this.y + z
       }};
    var b = { y: 20, __proto__: a };
    var c = { y: 30, __proto__: a };

    b.calculate(30); //60
    c.calculate(40); //80
•        “对          ”调          时 this   对
prototype chain
•   object     认prototype
    Object.prototype

•       认为Object       Class
        object    Object
    instance

•   实际 Object          function
Constructor
•   function Foo(y) { this.y = y; }
    Foo.prototype.x = 10;
    Foo.prototype.calculate = function(z) {
       return this.x + this.y + z;
     }
    var b = new Foo(20);
    var c = new Foo(30);
    b.calculate(30); //60
    c.calculate(40); //80
•        这样        new Foo(20);

    •   var new_instance = { __proto__: Foo.prototype };
        Foo.call(new_instance, 20);
    •   Foo         function      Function    instance     __proto__
        Function.prototype
    •   call   Function.prototype      义                       this
Constructor
String literal
•   Instance           •   Constructor

•   {}                 •   Object

•   []                 •   Array

•   function() {}      •   Function

•   2                  •   Number

•   true               •   Boolean
Quiz
•   typeof Function ?
•   typeof Function.__proto__ ?
•   typeof Function.prototype ?
•   Function.__proto__ == Function.prototype ?
•   var Foo = function() {};
    typeof Foo
    typeof Foo.prototype ?
    typeof Foo.__proto__ ?
    typeof Foo.prototype.constructor ?
Execution Context
         Stack
• global, function, eval (EC)
• global EC
• function EC                   执
Execution Context


• EC   object
Variable Object
•   global EC VO

    •   var foo = 10;
        function bar() {};
•   function EC     VO

    •   function foo(x, y) {
           var z = 30;
           function bar() {}
        }
        foo(10, 20);
Scope Chain

•         prototype chain      查
    询“member variables” path

•       scope chain            查询“lexical
    variables” path
Scope Chain
• var x = 10;
  (function foo() {
     var y = 20;
     (function bar() {
        var z = 30;
        console.log(x + y + z);
     })();
  })();
__parent__

• __parent__        function   时

• global        义     __parent__    global
    VO
•    function     义    __parent__
    function VO
Closures
• var foo = function() {
        var x = 10;
    }
    foo();
•         foo()              VO    这
    VO                对           foo()执
    结             x
Closures
•   var foo = function() {
       var x = 10;
       return function() { console.log(x) };
    }
    var boo1 = foo();
    var boo2 = foo();
•   这    foo         执                function boo1 boo2
      VO       __parent__                foo VO       实
                  boo1      boo2           应 foo VO
Closures - Quiz

• var x = 10;
  function foo() { console.log(x, y); }
  (function (funArg) {
      var x = 20;
      var y = 30;
      funArg();
  })(foo);
Closures - Quiz
•   function baz() {
       var x = 1;
       return {
          foo: function foo() { return ++x; },
          bar: function bar() { return --x; }
       };
    }
    var closures = baz();

    closures.foo();
    closures.bar();
Closures
this

• function() this global
• obj.function() this obj
• function.call(obj) this obj
• new function() this           obj
Q &A
The End

More Related Content

What's hot

All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
Moriyoshi Koizumi
 
深入浅出Jscex
深入浅出Jscex深入浅出Jscex
深入浅出Jscex
jeffz
 
C++totural file
C++totural fileC++totural file
C++totural file
halaisumit
 
Jscex: Write Sexy JavaScript (中文)
Jscex: Write Sexy JavaScript (中文)Jscex: Write Sexy JavaScript (中文)
Jscex: Write Sexy JavaScript (中文)
jeffz
 

What's hot (20)

Functional "Life": parallel cellular automata and comonads
Functional "Life": parallel cellular automata and comonadsFunctional "Life": parallel cellular automata and comonads
Functional "Life": parallel cellular automata and comonads
 
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
 
미려한 UI/UX를 위한 여정
미려한 UI/UX를 위한 여정미려한 UI/UX를 위한 여정
미려한 UI/UX를 위한 여정
 
C++ Programming - 1st Study
C++ Programming - 1st StudyC++ Programming - 1st Study
C++ Programming - 1st Study
 
响应式编程及框架
响应式编程及框架响应式编程及框架
响应式编程及框架
 
C++ Programming - 11th Study
C++ Programming - 11th StudyC++ Programming - 11th Study
C++ Programming - 11th Study
 
Swift 0x0c 서브스크립트
Swift 0x0c 서브스크립트Swift 0x0c 서브스크립트
Swift 0x0c 서브스크립트
 
C++ Programming - 2nd Study
C++ Programming - 2nd StudyC++ Programming - 2nd Study
C++ Programming - 2nd Study
 
C++ Lambda and concurrency
C++ Lambda and concurrencyC++ Lambda and concurrency
C++ Lambda and concurrency
 
Burrowing through go! the book
Burrowing through go! the bookBurrowing through go! the book
Burrowing through go! the book
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
 
C++ tutorial
C++ tutorialC++ tutorial
C++ tutorial
 
深入浅出Jscex
深入浅出Jscex深入浅出Jscex
深入浅出Jscex
 
openFrameworks 007 - 3D
openFrameworks 007 - 3DopenFrameworks 007 - 3D
openFrameworks 007 - 3D
 
C++totural file
C++totural fileC++totural file
C++totural file
 
JavaScript: enter the dragon
JavaScript: enter the dragonJavaScript: enter the dragon
JavaScript: enter the dragon
 
Jscex: Write Sexy JavaScript (中文)
Jscex: Write Sexy JavaScript (中文)Jscex: Write Sexy JavaScript (中文)
Jscex: Write Sexy JavaScript (中文)
 
Javascript OOP
Javascript OOPJavascript OOP
Javascript OOP
 
Functors, applicatives, monads
Functors, applicatives, monadsFunctors, applicatives, monads
Functors, applicatives, monads
 
Exploring slides
Exploring slidesExploring slides
Exploring slides
 

Viewers also liked (7)

the perception of style
the perception of stylethe perception of style
the perception of style
 
Presentacio Amb Programari Lliure
Presentacio Amb Programari LliurePresentacio Amb Programari Lliure
Presentacio Amb Programari Lliure
 
Quickstart
QuickstartQuickstart
Quickstart
 
Lic225 licitacion publica internacional 05 adq-ucpp-2007100-avisodeprensa
Lic225 licitacion publica internacional 05 adq-ucpp-2007100-avisodeprensaLic225 licitacion publica internacional 05 adq-ucpp-2007100-avisodeprensa
Lic225 licitacion publica internacional 05 adq-ucpp-2007100-avisodeprensa
 
The expectedness of style
The expectedness of styleThe expectedness of style
The expectedness of style
 
Partition Manager 11 - Paragon Software
Partition Manager 11 - Paragon SoftwarePartition Manager 11 - Paragon Software
Partition Manager 11 - Paragon Software
 
Calendario 2016 con caratula
Calendario 2016 con caratulaCalendario 2016 con caratula
Calendario 2016 con caratula
 

Similar to Javascript - The core

Front end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript coreFront end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript core
Web Zhao
 
Javascript Uncommon Programming
Javascript Uncommon ProgrammingJavascript Uncommon Programming
Javascript Uncommon Programming
jeffz
 
みゆっき☆Think#7 「本気で学ぶJavascript」
みゆっき☆Think#7 「本気で学ぶJavascript」みゆっき☆Think#7 「本気で学ぶJavascript」
みゆっき☆Think#7 「本気で学ぶJavascript」
techtalkdwango
 
第7回みゆっき☆Think 本気で学ぶ JavaScript
第7回みゆっき☆Think 本気で学ぶ JavaScript第7回みゆっき☆Think 本気で学ぶ JavaScript
第7回みゆっき☆Think 本気で学ぶ JavaScript
Takuya Fujimura
 
ECMAScript 6 major changes
ECMAScript 6 major changesECMAScript 6 major changes
ECMAScript 6 major changes
hayato
 
JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for Dummies
Charles Nutter
 
ぐだ生 Java入門第一回(equals hash code_tostring)
ぐだ生 Java入門第一回(equals hash code_tostring)ぐだ生 Java入門第一回(equals hash code_tostring)
ぐだ生 Java入門第一回(equals hash code_tostring)
Makoto Yamazaki
 
Get started with YUI
Get started with YUIGet started with YUI
Get started with YUI
Adam Lu
 
Prototype 120102020133-phpapp02
Prototype 120102020133-phpapp02Prototype 120102020133-phpapp02
Prototype 120102020133-phpapp02
plutoone TestTwo
 

Similar to Javascript - The core (20)

JavaScript Primer
JavaScript PrimerJavaScript Primer
JavaScript Primer
 
Front end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript coreFront end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript core
 
ECMA 入门
ECMA 入门ECMA 入门
ECMA 入门
 
Awesomeness of JavaScript…almost
Awesomeness of JavaScript…almostAwesomeness of JavaScript…almost
Awesomeness of JavaScript…almost
 
Javascript Uncommon Programming
Javascript Uncommon ProgrammingJavascript Uncommon Programming
Javascript Uncommon Programming
 
みゆっき☆Think#7 「本気で学ぶJavascript」
みゆっき☆Think#7 「本気で学ぶJavascript」みゆっき☆Think#7 「本気で学ぶJavascript」
みゆっき☆Think#7 「本気で学ぶJavascript」
 
第7回みゆっき☆Think 本気で学ぶ JavaScript
第7回みゆっき☆Think 本気で学ぶ JavaScript第7回みゆっき☆Think 本気で学ぶ JavaScript
第7回みゆっき☆Think 本気で学ぶ JavaScript
 
ECMAScript 6 major changes
ECMAScript 6 major changesECMAScript 6 major changes
ECMAScript 6 major changes
 
サイ本 文
サイ本 文サイ本 文
サイ本 文
 
JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for Dummies
 
JavaScript - Object-Oriented Programming & Remote Scripting
JavaScript - Object-Oriented Programming & Remote ScriptingJavaScript - Object-Oriented Programming & Remote Scripting
JavaScript - Object-Oriented Programming & Remote Scripting
 
Learn JavaScript by modeling Rubik Cube
Learn JavaScript by modeling Rubik CubeLearn JavaScript by modeling Rubik Cube
Learn JavaScript by modeling Rubik Cube
 
ぐだ生 Java入門第一回(equals hash code_tostring)
ぐだ生 Java入門第一回(equals hash code_tostring)ぐだ生 Java入門第一回(equals hash code_tostring)
ぐだ生 Java入門第一回(equals hash code_tostring)
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformation
 
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
 
Ajaxworld
AjaxworldAjaxworld
Ajaxworld
 
Get started with YUI
Get started with YUIGet started with YUI
Get started with YUI
 
JavaScript Unit Testing with Jasmine
JavaScript Unit Testing with JasmineJavaScript Unit Testing with Jasmine
JavaScript Unit Testing with Jasmine
 
Prototype 120102020133-phpapp02
Prototype 120102020133-phpapp02Prototype 120102020133-phpapp02
Prototype 120102020133-phpapp02
 
Realm: Building a mobile database
Realm: Building a mobile databaseRealm: Building a mobile database
Realm: Building a mobile database
 

Recently uploaded

Recently uploaded (20)

Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 

Javascript - The core

  • 2. object • Javascript ( int) object • function object • object拥 组properties 为 null prototype
  • 3. object • 义 var foo = { x:10, y: 20 }; • 读 foo.x OR foo[‘x’] • 设 foo.x = 123 OR foo[‘x’] = 123 • 动态获 时
  • 4. object • prototype object • 过__proto__ prototype • foo.__proto__ OR foo[‘__proto__’]
  • 5. prototype chain • object 过__proto__ 实现继 property • property 查 规则 • __proto__为null为 • property
  • 6. prototype chain • var a = { x: 10, calculate: function(z) { return this.x + this.y + z }}; var b = { y: 20, __proto__: a }; var c = { y: 30, __proto__: a }; b.calculate(30); //60 c.calculate(40); //80 • “对 ”调 时 this 对
  • 7. prototype chain • object 认prototype Object.prototype • 认为Object Class object Object instance • 实际 Object function
  • 8. Constructor • function Foo(y) { this.y = y; } Foo.prototype.x = 10; Foo.prototype.calculate = function(z) { return this.x + this.y + z; } var b = new Foo(20); var c = new Foo(30); b.calculate(30); //60 c.calculate(40); //80 • 这样 new Foo(20); • var new_instance = { __proto__: Foo.prototype }; Foo.call(new_instance, 20); • Foo function Function instance __proto__ Function.prototype • call Function.prototype 义 this
  • 10. String literal • Instance • Constructor • {} • Object • [] • Array • function() {} • Function • 2 • Number • true • Boolean
  • 11. Quiz • typeof Function ? • typeof Function.__proto__ ? • typeof Function.prototype ? • Function.__proto__ == Function.prototype ? • var Foo = function() {}; typeof Foo typeof Foo.prototype ? typeof Foo.__proto__ ? typeof Foo.prototype.constructor ?
  • 12. Execution Context Stack • global, function, eval (EC) • global EC • function EC 执
  • 14. Variable Object • global EC VO • var foo = 10; function bar() {}; • function EC VO • function foo(x, y) { var z = 30; function bar() {} } foo(10, 20);
  • 15. Scope Chain • prototype chain 查 询“member variables” path • scope chain 查询“lexical variables” path
  • 16. Scope Chain • var x = 10; (function foo() { var y = 20; (function bar() { var z = 30; console.log(x + y + z); })(); })();
  • 17. __parent__ • __parent__ function 时 • global 义 __parent__ global VO • function 义 __parent__ function VO
  • 18. Closures • var foo = function() { var x = 10; } foo(); • foo() VO 这 VO 对 foo()执 结 x
  • 19. Closures • var foo = function() { var x = 10; return function() { console.log(x) }; } var boo1 = foo(); var boo2 = foo(); • 这 foo 执 function boo1 boo2 VO __parent__ foo VO 实 boo1 boo2 应 foo VO
  • 20. Closures - Quiz • var x = 10; function foo() { console.log(x, y); } (function (funArg) { var x = 20; var y = 30; funArg(); })(foo);
  • 21. Closures - Quiz • function baz() { var x = 1; return { foo: function foo() { return ++x; }, bar: function bar() { return --x; } }; } var closures = baz(); closures.foo(); closures.bar();
  • 23. this • function() this global • obj.function() this obj • function.call(obj) this obj • new function() this obj
  • 24. Q &A

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n