SlideShare a Scribd company logo
1 of 34
Download to read offline
Script ing




             Wang_Wei@opi-corp.com
Content

1.Programming Paradigm 编程范式
2.Addressing 寻址、属性访问
3.Inheritance 继承
4.Scope 作用域
5.Closure 闭包
6.Embedding Script Engine 嵌入脚本引擎
7.JavaScript V8 Performance V8性能
8.Resources 一些链接和书籍
Benefits
•No compile, no build. Just Code and Test
•Very, very short design cycles
•Less code
•Absolute Flexibility.

让你的工作变得没那么枯燥,减少“体力活”
生成代码,瞬间产生大量代码,改善你的KPI数据....
扩展视野,给出更好的解决方案

                       Python Py2Exe
Script to Executable
                       Ruby Exerb
Compiler/Embeder
                       PHP Bambalam
                       Java GCJ
                       ...
1.Programming Paradigm
http://en.wikipedia.org/wiki/Comparison_of_programming_paradigms



Imperative 各种语句直接改变程序状态,全局数据,共同的数据类型
 ASM,C/C++/C#,Pascal,JavaScript...
  Structured 代码缩进,N-S盒图,不使用GOTO(针对汇编语言)
   C/C++/C#,Pascal,QB,JavaScript...
  Procedural 局部变量,顺序执行,条件判断,循环迭代,模块化
   C/C++/C#,Pascal,QB...
    Event-driven 主循环,事件响应,异步
     Win32SDK,Reactor Pattern:
     Mina,Netty,Boost.Asio,Twisted,EventMachine
     Browser DOM JavaScript
    Automata-based 状态机,状态切换,状态表
Object-oriented 面向对象
  C++,C#,Delphi,Python,Ruby,JavaScript,Lua....
Functional 函数式,匿名函数、delegate、lambda
  Scheme,Erlang,OCaml,Haskell,JavaScript,Ruby,F#,C#4
Declarative 声明式,只描述计算的逻辑,不描述具体细节
  XML,CSS,SQL,4GLs,Haskell,DSL,Effect Script,
1.Programming Paradigm
http://en.wikipedia.org/wiki/Comparison_
of_programming_paradigms


编程范式 Programming Paradigm
单个语言并不局限于某个范式

多范式编程语言 Multi-paradigm Programming Language
C++ : Procedural,Object-Oriented,Generic,Functional
C# : OO,Generic,Functional,Declarative
Ruby : Procedural,OO,Functional
JavaScript : OO,Functional
2.Addressing
Addressing
C/C++

               寄存器寻址、


               直接/间接内存寻
               址

               立即数
2.Addressing
Java

               操作数栈

               常量池

               立即数
Virtual function and vftable
http://hi.baidu.com/aztack/blog/item/9258b2355545a088a71e124c.html




     void main(int,char**)
     {
              C c;                 Disassemble...
              c.i = 123;
              c.f1();
     }
void main(int,char**)
{
         C c;
         c.i = 9;
         c.f1();
}
void main(int,char**)
“Object ” -                                  {
properties                                            C c;
                                                      c.i = 9;
                                                      c.f1();
                                             }

              “Object Reference” +
              properties




       this->f1();
                         “Function Object”
                         - socpe

                                                     goto page19
Virtual vs Non-Virtual
http://hi.baidu.com/aztack/blog/item/9258b2355545a088a71e124c.html

                                                                     0x00401100
                                                                      void f1(){...}
  0x0012FF70                       0x004060B0

   0x004060B0                        0x00401100                       void f2(){...}


    ......                                                            void f3(){...}

                                                                      void f4(){...}




 Stack                                Data                                Code

 Fastes Function Call : Non-Virutal               Add a layer of indirection to
 Call 0x4111C2F                                   implement Polymorphism
3.Prototype-based Inheritance
http://hi.baidu.com/aztack/blog/item/55ad0946b59268066a63e567.html
http://en.wikipedia.org/wiki/Prototype-based_programming



   GrandChild                      Parent                      GrandParent

    __proto__
  grandChild = {               parent = {               parent = {
     name:"Jack",                 name:"unnamed",          name:"unnamed",
     __proto__:parent
    name="Jack"                   F4:function(){...},      F1:function(){...}
  };                              __proto__:grandParent    F2:function(){...}
                               };                          F3:function(){...}
                                                        };

                              grandChild.F3();




Self,JavaScript,Lua,ActionScript,Falcon,Io,Ioke,Object Lisp
3.Prototype-based Inheritance
 http://hi.baidu.com/aztack/blog/item/55ad0946b59268066a63e567.html




    GrandChild                      Parent                      GrandParent

     __proto__                        __proto__                   __proto__
                                                                                 null
     name="Jack"                                                 function F1()
                                     name="unnamed"

                                                                 function F2()
                                      function F4()

      ?????????                       ????????                   function F3()


grand_child.F3()
                                Prototype-Chain


Prototype-Chain to implement Prototype-based Inheritance
3.Prototype-based Inheritance
 http://hi.baidu.com/aztack/blog/item/55ad0946b59268066a63e567.html




    GrandChild                      Parent                      GrandParent

     __proto__                        __proto__                   __proto__
                                                                                 null
     name="Jack"                                                 function F1()
                                     name="unnamed"

                                                                 function F2()
                                      function F4()

      ?????????                       ????????                   function F3()




Hash Map


More layer of indirection to implement
Prototype-based Inheritance
3.Prototype-based Inheritance
 http://hi.baidu.com/aztack/blog/item/55ad0946b59268066a63e567.html




    GrandChild                      Parent                      GrandParent

     __proto__                        __proto__                   __proto__
                                                                                        null
     name="Jack"                                                 function F1()
                                     name="unnamed"

                                                                 function F2()
                                      function F4()

      ?????????                       ????????                   function F3()




                              Linked List                    Prototype-based inheritance
                                                             share properties & methods
                                                             while classic inheritance only
More layer of indirection to implement                       share methods
Prototype-based Inheritance
Prototype in JavaScript & Lua
4.Scope




 Function Declaration            Function Expression
 function f1(){...}              function(){}




f1          function f1(){...}         function (){...}
4.Scope -    JavaScript has only function scope,nothing else




            Entering Executing Context

                      Code Execution
Hoisting:
函数、变量声明提升到最开始
5.Closure
all parent scopes
                       - A closure is a combination of a function and statically saved




Stack-Oriented Programming Language
At return from a function,it's local variables are removed from stack




                                                          ESP
                       ESP

                                                          1.Not set to zero
                                                          2.Accessible in c/c++!
                                                          3.Results Undefined
                                                          behavior
5.Closure
    all parent scopes
                                - A closure is a combination of a function and statically saved




    JavaScript                       anonymous                        Heap

                                                                       VO

                                                 Variable Object          data

                                                      local           __parent__
                                                      variable

                                                     __parent__     Scope-Chain!!!
          Function Object




                                                             Code
                                                             function(){
f                      [[Call]] this code with f()              print(data.str);
                                                             }
                             goto page9
5.Closure
 all parent scopes
                     - A closure is a combination of a function and statically saved




def entryExit(f):
   def new_f():
                                                            @entryExit
      print "Entering", new_f.__name__
                                                            def someFunc:pass
      f()
      print "Exited", new_f.__name__
   new_f.__name__ = f.__name__
   return new_f

function entryExit(f){
   function new_f(){
      print("Entring",new_f.__name__);
      f();
      print("Exited",new_f.__name__);
   }                                                        var f = entryExit(
   new_f.__name__ = f.name;                                  function(){...}
   return new_f;                                            );
}
Save function address and
             function name

make a callable object with
                 operator()

       consider number of
parameters and return type




       Boost preprocessor
                      and
Variadic Templates to help
5.Closure
all parent scopes
                                  - A closure is a combination of a function and statically saved




A common mistake : Creating closures in loops

   function setupHelp() {
    var helpText = [
       {'id': 'email', 'help': 'Your e-mail address'},
       {'id': 'name', 'help': 'Your full name'},
       {'id': 'age', 'help': 'Your age (you must be over 16)'}
     ];

       for (var i = 0; i < helpText.length; i++) {
         var item = helpText[i];
         document.getElementById(item.id).onfocus = function() {
           showHelp(item.help);
         }
       }
   }
https://developer.mozilla.org/en/JavaScript/Guide/Closures
5.Closure
all parent scopes
                                  - A closure is a combination of a function and statically saved




Fix: Avoid creating unneccessary stuffs in loops

   function setupHelp() {
     var helpText = {
         'email': 'Your e-mail address',
         'name': 'Your full name',
         'help': 'Your age (you must be over 16)'
       };
     function ShowHelp(){
         alert(helpText[this.id]);
     }
     for (var id in helpText) {
       document.getElementById(id).onfocus = showHelp
     }
   }

https://developer.mozilla.org/en/JavaScript/Guide/Closures
6.Embedding Script Engine

JavaScript V8 for C++   Chrome/Chromium/Node.js




                                      •
                                      •
                                      •
                                      •
                                      执注创初
                                      行册建始
                                      脚变执化
                                      本量行引
                                       和环擎
                                       函境可




                                             (
                                       数 选




                                             )
6.Embedding Script Engine
PaxScript for Delphi
6.Embedding Script Engine

JavaScript V8 for .Net
http://javascriptdotnet.codeplex.com/

IronRuby/IronPython for .Net
http://ironruby.net/         http://ironpython.net/


Lua,Ruby,Python,PHP,Java,TraceMonkey for C++

WoW      SketchUp             Firefox

JRuby,Jython,Rhino+BSF,Groovy,Scala...for Java

                        屠魔服务端 龙之刃
7.JavaScript V8 Performance
http://code.google.com/apis/v8/design.html



  •Fast Property Access




  •Dynamic Machine Code Generation
     point.x
     =>
     # ebx = the point object
     cmp [ebx,<hidden class offset>],<cached hidden class>
     jne <inline cache miss>
     mov eax,[ebx, <cached x offset>]
JavaScript V8 vs Lua
JavaScript V8 vs Python
Resources - people,books,links


             Dmitry A. Soshnikov
             http://dmitrysoshnikov.com




         developer.mozilla.org

                                          John Resig @mozilla
                                        http://ejohn.org/
    JavaScript Secrets Pro JavaScript
Resources - people,books,links

•ECMA-262-5th
•O'Reilly - Javascript - The Definitive Guide, 4th Edition
•Oreilly.High.Performance.JavaScript.Mar.2010
•Pro.JavaScript.Design.Patterns


•Professional.JavaScript.for.Web.Developers.2nd.Edition




                      Nicholas C. Zakas            @yahoo

                       http://www.nczonline.net/
Resources - people,books,links

          http://www.crockford.com


                             YUI blog
                            JavaScript
                      The Theory of the Dom
                       Advanced JavaScript
                           Browser Wars
                              Quality
                    JavaScript: The Good Stuff
                         The State of Ajax
                          The JSON Saga
                         Ajax Performance
                 The State and Future of JavaScript




               Douglas Crockford @yahoo
Wang_Wei@opi-corp.com

More Related Content

What's hot

닷넷 개발자를 위한 패턴이야기
닷넷 개발자를 위한 패턴이야기닷넷 개발자를 위한 패턴이야기
닷넷 개발자를 위한 패턴이야기YoungSu Son
 
2 + 2 = 5: Monkey-patching CPython with ctypes to conform to Party doctrine
2 + 2 = 5: Monkey-patching CPython with ctypes to conform to Party doctrine2 + 2 = 5: Monkey-patching CPython with ctypes to conform to Party doctrine
2 + 2 = 5: Monkey-patching CPython with ctypes to conform to Party doctrineFrankie Dintino
 
Notes for xx_use_serialgc
Notes for xx_use_serialgcNotes for xx_use_serialgc
Notes for xx_use_serialgcytoshima
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoinknight1128
 
C# for-java-developers
C# for-java-developersC# for-java-developers
C# for-java-developersDhaval Dalal
 
OpenGurukul : Language : PHP
OpenGurukul : Language : PHPOpenGurukul : Language : PHP
OpenGurukul : Language : PHPOpen Gurukul
 
Fundamental of programming - مقدمات برنامه نویسی
Fundamental of programming - مقدمات برنامه نویسیFundamental of programming - مقدمات برنامه نویسی
Fundamental of programming - مقدمات برنامه نویسیSaman Chitsazian
 
ITGM #9 - Коварный CodeType, или от segfault'а к работающему коду
ITGM #9 - Коварный CodeType, или от segfault'а к работающему кодуITGM #9 - Коварный CodeType, или от segfault'а к работающему коду
ITGM #9 - Коварный CodeType, или от segfault'а к работающему кодуdelimitry
 
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code styleRuby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code styleAnton Shemerey
 
김재석, C++ 프로그래머를 위한 C#, NDC2011
김재석, C++ 프로그래머를 위한 C#, NDC2011김재석, C++ 프로그래머를 위한 C#, NDC2011
김재석, C++ 프로그래머를 위한 C#, NDC2011devCAT Studio, NEXON
 
平成22年度情報通信工学実験IB実施資料
平成22年度情報通信工学実験IB実施資料平成22年度情報通信工学実験IB実施資料
平成22年度情報通信工学実験IB実施資料Takeo Kunishima
 
35787646 system-software-lab-manual
35787646 system-software-lab-manual35787646 system-software-lab-manual
35787646 system-software-lab-manualNaveen Kumar
 
Unit testing without Robolectric, Droidcon Berlin 2016
Unit testing without Robolectric, Droidcon Berlin 2016Unit testing without Robolectric, Droidcon Berlin 2016
Unit testing without Robolectric, Droidcon Berlin 2016Danny Preussler
 
Антон Нонко, Классические строки в C++
Антон Нонко, Классические строки в C++Антон Нонко, Классические строки в C++
Антон Нонко, Классические строки в C++Sergey Platonov
 
HotSpot template interpreter memos
HotSpot template interpreter memosHotSpot template interpreter memos
HotSpot template interpreter memosytoshima
 
Memories of Bug Fixes
Memories of Bug FixesMemories of Bug Fixes
Memories of Bug FixesSung Kim
 
Create a Customized GMF DnD Framework
Create a Customized GMF DnD FrameworkCreate a Customized GMF DnD Framework
Create a Customized GMF DnD FrameworkKaniska Mandal
 

What's hot (20)

닷넷 개발자를 위한 패턴이야기
닷넷 개발자를 위한 패턴이야기닷넷 개발자를 위한 패턴이야기
닷넷 개발자를 위한 패턴이야기
 
2 + 2 = 5: Monkey-patching CPython with ctypes to conform to Party doctrine
2 + 2 = 5: Monkey-patching CPython with ctypes to conform to Party doctrine2 + 2 = 5: Monkey-patching CPython with ctypes to conform to Party doctrine
2 + 2 = 5: Monkey-patching CPython with ctypes to conform to Party doctrine
 
Notes for xx_use_serialgc
Notes for xx_use_serialgcNotes for xx_use_serialgc
Notes for xx_use_serialgc
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoin
 
C# for-java-developers
C# for-java-developersC# for-java-developers
C# for-java-developers
 
OpenGurukul : Language : PHP
OpenGurukul : Language : PHPOpenGurukul : Language : PHP
OpenGurukul : Language : PHP
 
Regexp master 2011
Regexp master 2011Regexp master 2011
Regexp master 2011
 
Fundamental of programming - مقدمات برنامه نویسی
Fundamental of programming - مقدمات برنامه نویسیFundamental of programming - مقدمات برنامه نویسی
Fundamental of programming - مقدمات برنامه نویسی
 
Test2 Sum05
Test2 Sum05Test2 Sum05
Test2 Sum05
 
ITGM #9 - Коварный CodeType, или от segfault'а к работающему коду
ITGM #9 - Коварный CodeType, или от segfault'а к работающему кодуITGM #9 - Коварный CodeType, или от segfault'а к работающему коду
ITGM #9 - Коварный CodeType, или от segfault'а к работающему коду
 
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code styleRuby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
 
김재석, C++ 프로그래머를 위한 C#, NDC2011
김재석, C++ 프로그래머를 위한 C#, NDC2011김재석, C++ 프로그래머를 위한 C#, NDC2011
김재석, C++ 프로그래머를 위한 C#, NDC2011
 
PHP 7
PHP 7PHP 7
PHP 7
 
平成22年度情報通信工学実験IB実施資料
平成22年度情報通信工学実験IB実施資料平成22年度情報通信工学実験IB実施資料
平成22年度情報通信工学実験IB実施資料
 
35787646 system-software-lab-manual
35787646 system-software-lab-manual35787646 system-software-lab-manual
35787646 system-software-lab-manual
 
Unit testing without Robolectric, Droidcon Berlin 2016
Unit testing without Robolectric, Droidcon Berlin 2016Unit testing without Robolectric, Droidcon Berlin 2016
Unit testing without Robolectric, Droidcon Berlin 2016
 
Антон Нонко, Классические строки в C++
Антон Нонко, Классические строки в C++Антон Нонко, Классические строки в C++
Антон Нонко, Классические строки в C++
 
HotSpot template interpreter memos
HotSpot template interpreter memosHotSpot template interpreter memos
HotSpot template interpreter memos
 
Memories of Bug Fixes
Memories of Bug FixesMemories of Bug Fixes
Memories of Bug Fixes
 
Create a Customized GMF DnD Framework
Create a Customized GMF DnD FrameworkCreate a Customized GMF DnD Framework
Create a Customized GMF DnD Framework
 

Similar to Here are the key points about closures:- A closure is a function that remembers values in enclosing scopes even if they are not present in memory. - In JavaScript, each function is a closure - it remembers its lexical scope through the scope chain.- Closures are created every time a function is created, at function creation time. - This allows a function defined inside another function to access variables from the parent function's scope.- The parent function and its variables effectively become part of the closed over function's scope.- Closures are useful for private variables, modules, and objects with methods.- In languages like JavaScript, closures solve the problem of referencing

Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleThierry Wasylczenko
 
Unbundling the JavaScript module bundler - DublinJS July 2018
Unbundling the JavaScript module bundler - DublinJS July 2018Unbundling the JavaScript module bundler - DublinJS July 2018
Unbundling the JavaScript module bundler - DublinJS July 2018Luciano Mammino
 
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.Jin-Hwa Kim
 
[C++ Korea] Effective Modern C++ Study, Item 11 - 13
[C++ Korea] Effective Modern C++ Study, Item 11 - 13[C++ Korea] Effective Modern C++ Study, Item 11 - 13
[C++ Korea] Effective Modern C++ Study, Item 11 - 13Chris Ohk
 
JavaOne 2015: From Java Code to Machine Code
JavaOne 2015: From Java Code to Machine CodeJavaOne 2015: From Java Code to Machine Code
JavaOne 2015: From Java Code to Machine CodeChris Bailey
 
Unbundling the JavaScript module bundler - Øredev 21 Nov 2018
Unbundling the JavaScript module bundler - Øredev 21 Nov 2018Unbundling the JavaScript module bundler - Øredev 21 Nov 2018
Unbundling the JavaScript module bundler - Øredev 21 Nov 2018Luciano Mammino
 
Catch a spider monkey
Catch a spider monkeyCatch a spider monkey
Catch a spider monkeyChengHui Weng
 
The mighty js_function
The mighty js_functionThe mighty js_function
The mighty js_functiontimotheeg
 
Unbundling the JavaScript module bundler - DevIT
Unbundling the JavaScript module bundler - DevITUnbundling the JavaScript module bundler - DevIT
Unbundling the JavaScript module bundler - DevITLuciano Mammino
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerGarth Gilmour
 
Javascript Prototype Visualized
Javascript Prototype VisualizedJavascript Prototype Visualized
Javascript Prototype Visualized军 沈
 
Pure Java RAD and Scaffolding Tools Race
Pure Java RAD and Scaffolding Tools RacePure Java RAD and Scaffolding Tools Race
Pure Java RAD and Scaffolding Tools RaceBaruch Sadogursky
 
Unbundling the JavaScript module bundler - Road to Coderful
Unbundling the JavaScript module bundler - Road to CoderfulUnbundling the JavaScript module bundler - Road to Coderful
Unbundling the JavaScript module bundler - Road to CoderfulLuciano Mammino
 
From Java 6 to Java 7 reference
From Java 6 to Java 7 referenceFrom Java 6 to Java 7 reference
From Java 6 to Java 7 referenceGiacomo Veneri
 

Similar to Here are the key points about closures:- A closure is a function that remembers values in enclosing scopes even if they are not present in memory. - In JavaScript, each function is a closure - it remembers its lexical scope through the scope chain.- Closures are created every time a function is created, at function creation time. - This allows a function defined inside another function to access variables from the parent function's scope.- The parent function and its variables effectively become part of the closed over function's scope.- Closures are useful for private variables, modules, and objects with methods.- In languages like JavaScript, closures solve the problem of referencing (20)

Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
Unbundling the JavaScript module bundler - DublinJS July 2018
Unbundling the JavaScript module bundler - DublinJS July 2018Unbundling the JavaScript module bundler - DublinJS July 2018
Unbundling the JavaScript module bundler - DublinJS July 2018
 
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
JavaScript Closures for Dummies & JavaScript prototype, closures and OOP.
 
[C++ Korea] Effective Modern C++ Study, Item 11 - 13
[C++ Korea] Effective Modern C++ Study, Item 11 - 13[C++ Korea] Effective Modern C++ Study, Item 11 - 13
[C++ Korea] Effective Modern C++ Study, Item 11 - 13
 
JavaOne 2015: From Java Code to Machine Code
JavaOne 2015: From Java Code to Machine CodeJavaOne 2015: From Java Code to Machine Code
JavaOne 2015: From Java Code to Machine Code
 
Tomorrow Java
Tomorrow JavaTomorrow Java
Tomorrow Java
 
Unbundling the JavaScript module bundler - Øredev 21 Nov 2018
Unbundling the JavaScript module bundler - Øredev 21 Nov 2018Unbundling the JavaScript module bundler - Øredev 21 Nov 2018
Unbundling the JavaScript module bundler - Øredev 21 Nov 2018
 
Catch a spider monkey
Catch a spider monkeyCatch a spider monkey
Catch a spider monkey
 
The mighty js_function
The mighty js_functionThe mighty js_function
The mighty js_function
 
interface
interfaceinterface
interface
 
Unbundling the JavaScript module bundler - DevIT
Unbundling the JavaScript module bundler - DevITUnbundling the JavaScript module bundler - DevIT
Unbundling the JavaScript module bundler - DevIT
 
Constructor and destructor
Constructor and destructorConstructor and destructor
Constructor and destructor
 
Javascript Best Practices
Javascript Best PracticesJavascript Best Practices
Javascript Best Practices
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
 
Javascript Prototype Visualized
Javascript Prototype VisualizedJavascript Prototype Visualized
Javascript Prototype Visualized
 
Pure Java RAD and Scaffolding Tools Race
Pure Java RAD and Scaffolding Tools RacePure Java RAD and Scaffolding Tools Race
Pure Java RAD and Scaffolding Tools Race
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
New in php 7
New in php 7New in php 7
New in php 7
 
Unbundling the JavaScript module bundler - Road to Coderful
Unbundling the JavaScript module bundler - Road to CoderfulUnbundling the JavaScript module bundler - Road to Coderful
Unbundling the JavaScript module bundler - Road to Coderful
 
From Java 6 to Java 7 reference
From Java 6 to Java 7 referenceFrom Java 6 to Java 7 reference
From Java 6 to Java 7 reference
 

Recently uploaded

ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 

Recently uploaded (20)

ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 

Here are the key points about closures:- A closure is a function that remembers values in enclosing scopes even if they are not present in memory. - In JavaScript, each function is a closure - it remembers its lexical scope through the scope chain.- Closures are created every time a function is created, at function creation time. - This allows a function defined inside another function to access variables from the parent function's scope.- The parent function and its variables effectively become part of the closed over function's scope.- Closures are useful for private variables, modules, and objects with methods.- In languages like JavaScript, closures solve the problem of referencing

  • 1. Script ing Wang_Wei@opi-corp.com
  • 2. Content 1.Programming Paradigm 编程范式 2.Addressing 寻址、属性访问 3.Inheritance 继承 4.Scope 作用域 5.Closure 闭包 6.Embedding Script Engine 嵌入脚本引擎 7.JavaScript V8 Performance V8性能 8.Resources 一些链接和书籍
  • 3. Benefits •No compile, no build. Just Code and Test •Very, very short design cycles •Less code •Absolute Flexibility. 让你的工作变得没那么枯燥,减少“体力活” 生成代码,瞬间产生大量代码,改善你的KPI数据.... 扩展视野,给出更好的解决方案 Python Py2Exe Script to Executable Ruby Exerb Compiler/Embeder PHP Bambalam Java GCJ ...
  • 4. 1.Programming Paradigm http://en.wikipedia.org/wiki/Comparison_of_programming_paradigms Imperative 各种语句直接改变程序状态,全局数据,共同的数据类型 ASM,C/C++/C#,Pascal,JavaScript... Structured 代码缩进,N-S盒图,不使用GOTO(针对汇编语言) C/C++/C#,Pascal,QB,JavaScript... Procedural 局部变量,顺序执行,条件判断,循环迭代,模块化 C/C++/C#,Pascal,QB... Event-driven 主循环,事件响应,异步 Win32SDK,Reactor Pattern: Mina,Netty,Boost.Asio,Twisted,EventMachine Browser DOM JavaScript Automata-based 状态机,状态切换,状态表 Object-oriented 面向对象 C++,C#,Delphi,Python,Ruby,JavaScript,Lua.... Functional 函数式,匿名函数、delegate、lambda Scheme,Erlang,OCaml,Haskell,JavaScript,Ruby,F#,C#4 Declarative 声明式,只描述计算的逻辑,不描述具体细节 XML,CSS,SQL,4GLs,Haskell,DSL,Effect Script,
  • 5. 1.Programming Paradigm http://en.wikipedia.org/wiki/Comparison_ of_programming_paradigms 编程范式 Programming Paradigm 单个语言并不局限于某个范式 多范式编程语言 Multi-paradigm Programming Language C++ : Procedural,Object-Oriented,Generic,Functional C# : OO,Generic,Functional,Declarative Ruby : Procedural,OO,Functional JavaScript : OO,Functional
  • 6. 2.Addressing Addressing C/C++ 寄存器寻址、 直接/间接内存寻 址 立即数
  • 7. 2.Addressing Java 操作数栈 常量池 立即数
  • 8. Virtual function and vftable http://hi.baidu.com/aztack/blog/item/9258b2355545a088a71e124c.html void main(int,char**) { C c; Disassemble... c.i = 123; c.f1(); }
  • 9. void main(int,char**) { C c; c.i = 9; c.f1(); }
  • 10. void main(int,char**) “Object ” - { properties C c; c.i = 9; c.f1(); } “Object Reference” + properties this->f1(); “Function Object” - socpe goto page19
  • 11. Virtual vs Non-Virtual http://hi.baidu.com/aztack/blog/item/9258b2355545a088a71e124c.html 0x00401100 void f1(){...} 0x0012FF70 0x004060B0 0x004060B0 0x00401100 void f2(){...} ...... void f3(){...} void f4(){...} Stack Data Code Fastes Function Call : Non-Virutal Add a layer of indirection to Call 0x4111C2F implement Polymorphism
  • 12. 3.Prototype-based Inheritance http://hi.baidu.com/aztack/blog/item/55ad0946b59268066a63e567.html http://en.wikipedia.org/wiki/Prototype-based_programming GrandChild Parent GrandParent __proto__ grandChild = { parent = { parent = { name:"Jack", name:"unnamed", name:"unnamed", __proto__:parent name="Jack" F4:function(){...}, F1:function(){...} }; __proto__:grandParent F2:function(){...} }; F3:function(){...} }; grandChild.F3(); Self,JavaScript,Lua,ActionScript,Falcon,Io,Ioke,Object Lisp
  • 13. 3.Prototype-based Inheritance http://hi.baidu.com/aztack/blog/item/55ad0946b59268066a63e567.html GrandChild Parent GrandParent __proto__ __proto__ __proto__ null name="Jack" function F1() name="unnamed" function F2() function F4() ????????? ???????? function F3() grand_child.F3() Prototype-Chain Prototype-Chain to implement Prototype-based Inheritance
  • 14. 3.Prototype-based Inheritance http://hi.baidu.com/aztack/blog/item/55ad0946b59268066a63e567.html GrandChild Parent GrandParent __proto__ __proto__ __proto__ null name="Jack" function F1() name="unnamed" function F2() function F4() ????????? ???????? function F3() Hash Map More layer of indirection to implement Prototype-based Inheritance
  • 15. 3.Prototype-based Inheritance http://hi.baidu.com/aztack/blog/item/55ad0946b59268066a63e567.html GrandChild Parent GrandParent __proto__ __proto__ __proto__ null name="Jack" function F1() name="unnamed" function F2() function F4() ????????? ???????? function F3() Linked List Prototype-based inheritance share properties & methods while classic inheritance only More layer of indirection to implement share methods Prototype-based Inheritance
  • 17. 4.Scope Function Declaration Function Expression function f1(){...} function(){} f1 function f1(){...} function (){...}
  • 18. 4.Scope - JavaScript has only function scope,nothing else Entering Executing Context Code Execution Hoisting: 函数、变量声明提升到最开始
  • 19. 5.Closure all parent scopes - A closure is a combination of a function and statically saved Stack-Oriented Programming Language At return from a function,it's local variables are removed from stack ESP ESP 1.Not set to zero 2.Accessible in c/c++! 3.Results Undefined behavior
  • 20. 5.Closure all parent scopes - A closure is a combination of a function and statically saved JavaScript anonymous Heap VO Variable Object data local __parent__ variable __parent__ Scope-Chain!!! Function Object Code function(){ f [[Call]] this code with f() print(data.str); } goto page9
  • 21. 5.Closure all parent scopes - A closure is a combination of a function and statically saved def entryExit(f): def new_f(): @entryExit print "Entering", new_f.__name__ def someFunc:pass f() print "Exited", new_f.__name__ new_f.__name__ = f.__name__ return new_f function entryExit(f){ function new_f(){ print("Entring",new_f.__name__); f(); print("Exited",new_f.__name__); } var f = entryExit( new_f.__name__ = f.name; function(){...} return new_f; ); }
  • 22. Save function address and function name make a callable object with operator() consider number of parameters and return type Boost preprocessor and Variadic Templates to help
  • 23. 5.Closure all parent scopes - A closure is a combination of a function and statically saved A common mistake : Creating closures in loops function setupHelp() { var helpText = [ {'id': 'email', 'help': 'Your e-mail address'}, {'id': 'name', 'help': 'Your full name'}, {'id': 'age', 'help': 'Your age (you must be over 16)'} ]; for (var i = 0; i < helpText.length; i++) { var item = helpText[i]; document.getElementById(item.id).onfocus = function() { showHelp(item.help); } } } https://developer.mozilla.org/en/JavaScript/Guide/Closures
  • 24. 5.Closure all parent scopes - A closure is a combination of a function and statically saved Fix: Avoid creating unneccessary stuffs in loops function setupHelp() { var helpText = { 'email': 'Your e-mail address', 'name': 'Your full name', 'help': 'Your age (you must be over 16)' }; function ShowHelp(){ alert(helpText[this.id]); } for (var id in helpText) { document.getElementById(id).onfocus = showHelp } } https://developer.mozilla.org/en/JavaScript/Guide/Closures
  • 25. 6.Embedding Script Engine JavaScript V8 for C++ Chrome/Chromium/Node.js • • • • 执注创初 行册建始 脚变执化 本量行引 和环擎 函境可 ( 数 选 )
  • 27. 6.Embedding Script Engine JavaScript V8 for .Net http://javascriptdotnet.codeplex.com/ IronRuby/IronPython for .Net http://ironruby.net/ http://ironpython.net/ Lua,Ruby,Python,PHP,Java,TraceMonkey for C++ WoW SketchUp Firefox JRuby,Jython,Rhino+BSF,Groovy,Scala...for Java 屠魔服务端 龙之刃
  • 28. 7.JavaScript V8 Performance http://code.google.com/apis/v8/design.html •Fast Property Access •Dynamic Machine Code Generation point.x => # ebx = the point object cmp [ebx,<hidden class offset>],<cached hidden class> jne <inline cache miss> mov eax,[ebx, <cached x offset>]
  • 31. Resources - people,books,links Dmitry A. Soshnikov http://dmitrysoshnikov.com developer.mozilla.org John Resig @mozilla http://ejohn.org/ JavaScript Secrets Pro JavaScript
  • 32. Resources - people,books,links •ECMA-262-5th •O'Reilly - Javascript - The Definitive Guide, 4th Edition •Oreilly.High.Performance.JavaScript.Mar.2010 •Pro.JavaScript.Design.Patterns •Professional.JavaScript.for.Web.Developers.2nd.Edition Nicholas C. Zakas @yahoo http://www.nczonline.net/
  • 33. Resources - people,books,links http://www.crockford.com YUI blog JavaScript The Theory of the Dom Advanced JavaScript Browser Wars Quality JavaScript: The Good Stuff The State of Ajax The JSON Saga Ajax Performance The State and Future of JavaScript Douglas Crockford @yahoo