SlideShare a Scribd company logo
obvious secrets of

                           JavaScript



Monday, 21 December 2009
Monday, 21 December 2009
E very object (including host       objects) must implement the
                              e)) and ((Class)) propertie      s and the ((Get)), ((Put)),
                   ((Prototyp
                              t)), ((HasProperty)), ((Dele      te)), and ((DefaultValue))
                   ((CanPu
                              . (Note, however, that the ((D       efaultValue)) method may,
                   methods                                                  exception.) The value
                    for some objects    , simply throw a TypeError
                               Prototype)) property must be      either an object or null, and
                    of the ((
                               Prototype)) chain must have       finite length (that is, starting
                    every ((
                                y object, recursively access     ing the ((Prototype)) property
                     from an
                               entually lead to a null val         ue). Whether or not a native
                     must ev
                               an have a host object as its       ((Prototype)) depends on the
                     object c
                     implementation.
                          The value      of the ((Class)) property
                      is defined by        this specification for every
                      kind of built-i   n object. The value of the
                       ((Class)) prop    erty of a host object may
                       be any value     , even a value used by
Monday, 21 December 2009
E very object (including host       objects) must implement the
                              e)) and ((Class)) propertie      s and the ((Get)), ((Put)),
                   ((Prototyp
                              t)), ((HasProperty)), ((Dele      te)), and ((DefaultValue))
                   ((CanPu
                              . (Note, however, that the ((D       efaultValue)) method may,
                   methods                                                  exception.) The value
                    for some objects    , simply throw a TypeError
                               Prototype)) property must be      either an object or null, and
                    of the ((
                               Prototype)) chain must have       finite length (that is, starting
                    every ((
                                                                 ing the ((Prototype)) property
                     from an       It is a bit “cryptic”
                                y object, recursively access
                               entually lead to a null val         ue). Whether or not a native
                     must ev
                               an have a host object as its       ((Prototype)) depends on the
                     object c
                     implementation.
                          The value      of the ((Class)) property
                      is defined by        this specification for every
                      kind of built-i   n object. The value of the
                       ((Class)) prop    erty of a host object may
                       be any value     , even a value used by
Monday, 21 December 2009
Types




Monday, 21 December 2009
number      string

                           boolean    object

                             null    undefined



Monday, 21 December 2009
typeof
                           undefined      "undefined"

                              null         "object"

                            number         "number"

                           boolean         "boolean"

                             string        "string"

                            object         "object"


Monday, 21 December 2009
to Number
                           undefined         NaN

                              null            0

                            number            —

                           boolean     true→1, false→0

                             string        parsing

                            object       .valueOf()


Monday, 21 December 2009
to String
                           undefined       "undefined"

                              null           "null"

                            number             "5"

                           boolean           "true"

                             string              —

                            object         .toString()


Monday, 21 December 2009
to Boolean
                           undefined      FALSE

                              null        FALSE

                            number     0||NaN→false

                           boolean          —

                             string      ""→false

                            object         TRUE


Monday, 21 December 2009
to Object
                           undefined      exception!

                              null        exception!

                            number       new Number(5)

                           boolean     new Boolean(true)

                             string    new String("js")

                            object          object


Monday, 21 December 2009
5 + 4 + "px"
               "$" + 1 + 2
               "4" / "2"
               "$" + 1 - 2
               "web".length
               typeof 5
               typeof "5"
               typeof {key: value}
               typeof null
               typeof undefined
               typeof [1, 2, 3]
               typeof (4 - "px")
               +!{}[0]



Monday, 21 December 2009
5 + 4 + "px"          "9px"
               "$" + 1 + 2           "$12"
               "4" / "2"             2
               "$" + 1 - 2           NaN
               "web".length          3
               typeof 5              "number"
               typeof "5"            "string"
               typeof {key: value}   "object"
               typeof null           "object"
               typeof undefined      "undefined"
               typeof [1, 2, 3]      "object"
               typeof (4 - "px")     "number"
               +!{}[0]               1



Monday, 21 December 2009
Object Properties




Monday, 21 December 2009
for in




Monday, 21 December 2009
var a = {
                 x: 12,
                 y: 23,
                 r: 10,
                 draw: function () {/*...*/}
             };


             for (var property in a) {
                 alert("a." + property + " = " +
             a[property]);
             }




Monday, 21 December 2009
var a = {
                 x: 12,
                 y: 23,
                 r: 10,
                 draw: function () {/*...*/}
             };


             for (var property in a) {
                 alert("a." + property + " = " +
             a[property]);
             }




Monday, 21 December 2009
ReadOnly    DontEnum

                           DontDelete    Internal




Monday, 21 December 2009
Function




Monday, 21 December 2009
var y = 1;
             function x() {
                 var y = 2;
                 return ++y;
             }

             var z = function () {
                 return ++y;
             };




Monday, 21 December 2009
function x() {
                 var y = 2;
                 return function () {
                     return ++y;
                 };
             }

             var a = x();
             a();
             a();




Monday, 21 December 2009
typeof function (){} == "function"




Monday, 21 December 2009
Arguments




Monday, 21 December 2009
function add(a, b) {
                 return a + b;
             }

             add(4, 5); // = 9
             add(4, 5, 6, 7, 8, 9) // = 39

             function add() {
                 var sum = 0;
                 for (var i = 0, ii = arguments.length; i <
             ii; i++) {
                     sum +=+ arguments[i];
                 }
                 return sum;
             }


Monday, 21 December 2009
Scope, Context & “this”




Monday, 21 December 2009
function is(it) {
                 alert(this + " is " + it);
             }

             is("global");

             is.call(5, "number");

             is.apply("A", ["string"]);

             alert.is = is;

             alert.is("function");



Monday, 21 December 2009
Variable declaration




Monday, 21 December 2009
alert(b);
     1       b = 1;

             alert(a);
     2       var a = 1;

             (function () {
     3           var x = 1;
             })();
             alert(x);

             (function () {
     4           y = 1;
             })();
             alert(y);




Monday, 21 December 2009
Function declaration




Monday, 21 December 2009
function x(a) {
     1           return a && x(--a);
             }

             var x = function (a) {
     2           return a && x(--a);
             };

             setTimeout(function (a) {
     3           return a && arguments.callee(--a);
             }, 1000);

             var x = function y(a) {
     4           return a && y(--a);
             };

             setTimeout(function y(a) {
     5           return a && y(--a);
             }, 1000);



Monday, 21 December 2009
Array declaration




Monday, 21 December 2009
var a = new Array;

             var a = new Array(3);

             var a = [];

             var a = [undefined, undefined, undefined];

             var a = [1, 2, 3, 4];




Monday, 21 December 2009
Object declaration (JSON)




Monday, 21 December 2009
var a = new Object;

             var a = {};

             var a = {x: 10, y: 15};

             var a = {
                 x: 10,
                 name: "object",
                 "font-style": "italic",
                 getHeight: function () {/*...*/},
                 points: [1, 2, 3],
                 child: {x: 10, y: 15}
             };



Monday, 21 December 2009
OOP




Monday, 21 December 2009
Object Owns Prototype




Monday, 21 December 2009
var mouse = {
     1           name: "Mike",
                 voice: function () { alert("Squik!"); }
             };

             var o = new Object;
     2       o.name = "Mike";
             o.voice = function () { alert("Squik!"); };

             var O = function () {
     3           this.name = "Mike";
                 this.voice = function () { alert("Squik!"); };
             };
             var o = new O;

             var O = function () {};
     4       O.prototype.name = "Mike";
             O.prototype.voice = function () { alert("Squik!"); };
             var o = new O;



Monday, 21 December 2009
Inheritance




Monday, 21 December 2009
Delegation




Monday, 21 December 2009
Classic Model


                                         Class




                                                    Object
                                         Class




                           Object       Object      Object




Monday, 21 December 2009
Prototypal Model




                                                       Object




                           Object         Object       Object




Monday, 21 December 2009
var A = function () {};



                                1   A




Monday, 21 December 2009
var A = function () {};   x: 5
      A.prototype.x = 5;


                                 1     A




Monday, 21 December 2009
var A = function () {};   x: 5
      A.prototype.x = 5;

      var b = new A;
                                 1         A




                                       b




Monday, 21 December 2009
x: 5
      var A = function () {};   y: 6
      A.prototype.x = 5;

      var b = new A;
      A.prototype.y = 6;         1         A




                                       b




Monday, 21 December 2009
x: 5
      var A = function () {};   y: 6
      A.prototype.x = 5;

      var b = new A;
      A.prototype.y = 6;         1         A
      var c = new A;




                                       b   c




Monday, 21 December 2009
x: 5
      var A = function () {};   y: 6
      A.prototype.x = 5;

      var b = new A;
      A.prototype.y = 6;         1            A
      var c = new A;
      b.z = 7;




                                        b     c


                                       z: 7




Monday, 21 December 2009
x: 5
      var A = function () {};   y: 6
      A.prototype.x = 5;

      var b = new A;
      A.prototype.y = 6;         1            A
      var c = new A;
      b.z = 7;
      c.x = 4;



                                        b      c


                                       z: 7   x: 4




Monday, 21 December 2009
x: 5                 w: 1
      var A = function () {};   y: 6                 u: 2
      A.prototype.x = 5;

      var b = new A;
      A.prototype.y = 6;         1            A       2
      var c = new A;
      b.z = 7;
      c.x = 4;

      A.prototype = {
          w: 1,
          u: 2                          b      c
      };

                                       z: 7   x: 4




Monday, 21 December 2009
x: 5                         w: 1
      var A = function () {};   y: 6                         u: 2
      A.prototype.x = 5;

      var b = new A;
      A.prototype.y = 6;         1            A               2
      var c = new A;
      b.z = 7;
      c.x = 4;
                                                     *
      A.prototype = {
          w: 1,
          u: 2                          b      c         d
      };

      var d = new A;                   z: 7   x: 4       —




Monday, 21 December 2009
x: 5                         w: 1
      var A = function () {};   y: 6                         u: 2
      A.prototype.x = 5;

      var b = new A;
      A.prototype.y = 6;         1            A               2
      var c = new A;
      b.z = 7;
      c.x = 4;
                                                     *
      A.prototype = {
          w: 1,
          u: 2                          b      c         d
      };

      var d = new A;                   z: 7   x: 4       —




Monday, 21 December 2009
Thank You




Monday, 21 December 2009

More Related Content

What's hot

Using Reflections and Automatic Code Generation
Using Reflections and Automatic Code GenerationUsing Reflections and Automatic Code Generation
Using Reflections and Automatic Code Generation
Ivan Dolgushin
 
6.1.1一步一步学repast代码解释
6.1.1一步一步学repast代码解释6.1.1一步一步学repast代码解释
6.1.1一步一步学repast代码解释
zhang shuren
 
Google Dart
Google DartGoogle Dart
Google Dart
Eberhard Wolff
 
Objective c
Objective cObjective c
Objective c
ricky_chatur2005
 
Scala 2013 review
Scala 2013 reviewScala 2013 review
Scala 2013 review
Sagie Davidovich
 
Dependency Breaking Techniques
Dependency Breaking TechniquesDependency Breaking Techniques
Dependency Breaking Techniques
hyun soomyung
 
Ajaxworld
AjaxworldAjaxworld
Ajaxworld
deannalagason
 
Coding in Style
Coding in StyleCoding in Style
Coding in Style
scalaconfjp
 
Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013
aleks-f
 
tutorial5
tutorial5tutorial5
tutorial5
tutorialsruby
 
오브젝트C(pdf)
오브젝트C(pdf)오브젝트C(pdf)
오브젝트C(pdf)
sunwooindia
 
Mysterious c++
Mysterious c++Mysterious c++
Mysterious c++
xprayc
 
57200143 flash-action-script-quickref
57200143 flash-action-script-quickref57200143 flash-action-script-quickref
57200143 flash-action-script-quickref
pritam268
 
Treinamento Qt básico - aula III
Treinamento Qt básico - aula IIITreinamento Qt básico - aula III
Treinamento Qt básico - aula III
Marcelo Barros de Almeida
 
openFrameworks 007 - utils
openFrameworks 007 - utilsopenFrameworks 007 - utils
openFrameworks 007 - utils
roxlu
 
Observer pattern with Stl, boost and qt
Observer pattern with Stl, boost and qtObserver pattern with Stl, boost and qt
Observer pattern with Stl, boost and qt
Daniel Eriksson
 
05 - Qt External Interaction and Graphics
05 - Qt External Interaction and Graphics05 - Qt External Interaction and Graphics
05 - Qt External Interaction and Graphics
Andreas Jakl
 
Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
Skills Matter
 
响应式编程及框架
响应式编程及框架响应式编程及框架
响应式编程及框架
jeffz
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
Hiroshi Ono
 

What's hot (20)

Using Reflections and Automatic Code Generation
Using Reflections and Automatic Code GenerationUsing Reflections and Automatic Code Generation
Using Reflections and Automatic Code Generation
 
6.1.1一步一步学repast代码解释
6.1.1一步一步学repast代码解释6.1.1一步一步学repast代码解释
6.1.1一步一步学repast代码解释
 
Google Dart
Google DartGoogle Dart
Google Dart
 
Objective c
Objective cObjective c
Objective c
 
Scala 2013 review
Scala 2013 reviewScala 2013 review
Scala 2013 review
 
Dependency Breaking Techniques
Dependency Breaking TechniquesDependency Breaking Techniques
Dependency Breaking Techniques
 
Ajaxworld
AjaxworldAjaxworld
Ajaxworld
 
Coding in Style
Coding in StyleCoding in Style
Coding in Style
 
Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013
 
tutorial5
tutorial5tutorial5
tutorial5
 
오브젝트C(pdf)
오브젝트C(pdf)오브젝트C(pdf)
오브젝트C(pdf)
 
Mysterious c++
Mysterious c++Mysterious c++
Mysterious c++
 
57200143 flash-action-script-quickref
57200143 flash-action-script-quickref57200143 flash-action-script-quickref
57200143 flash-action-script-quickref
 
Treinamento Qt básico - aula III
Treinamento Qt básico - aula IIITreinamento Qt básico - aula III
Treinamento Qt básico - aula III
 
openFrameworks 007 - utils
openFrameworks 007 - utilsopenFrameworks 007 - utils
openFrameworks 007 - utils
 
Observer pattern with Stl, boost and qt
Observer pattern with Stl, boost and qtObserver pattern with Stl, boost and qt
Observer pattern with Stl, boost and qt
 
05 - Qt External Interaction and Graphics
05 - Qt External Interaction and Graphics05 - Qt External Interaction and Graphics
05 - Qt External Interaction and Graphics
 
Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
 
响应式编程及框架
响应式编程及框架响应式编程及框架
响应式编程及框架
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
 

Similar to Obvious Secrets of JavaScript

Java Script Workshop
Java Script WorkshopJava Script Workshop
Java Script Workshop
Dmitry Baranovskiy
 
ECMA 入门
ECMA 入门ECMA 入门
ECMA 入门
chencheng 云谦
 
ぐだ生 Java入門第一回(equals hash code_tostring)
ぐだ生 Java入門第一回(equals hash code_tostring)ぐだ生 Java入門第一回(equals hash code_tostring)
ぐだ生 Java入門第一回(equals hash code_tostring)
Makoto Yamazaki
 
tutorial5
tutorial5tutorial5
tutorial5
tutorialsruby
 
Scala Intro
Scala IntroScala Intro
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
 
Functional Programming in C++
Functional Programming in C++Functional Programming in C++
Functional Programming in C++
sankeld
 
GDSC NED Frontend Bootcamp Session 1.pptx
GDSC NED Frontend Bootcamp Session 1.pptxGDSC NED Frontend Bootcamp Session 1.pptx
GDSC NED Frontend Bootcamp Session 1.pptx
Ehtesham46
 
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
Heiko Behrens
 

Similar to Obvious Secrets of JavaScript (9)

Java Script Workshop
Java Script WorkshopJava Script Workshop
Java Script Workshop
 
ECMA 入门
ECMA 入门ECMA 入门
ECMA 入门
 
ぐだ生 Java入門第一回(equals hash code_tostring)
ぐだ生 Java入門第一回(equals hash code_tostring)ぐだ生 Java入門第一回(equals hash code_tostring)
ぐだ生 Java入門第一回(equals hash code_tostring)
 
tutorial5
tutorial5tutorial5
tutorial5
 
Scala Intro
Scala IntroScala Intro
Scala Intro
 
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
 
Functional Programming in C++
Functional Programming in C++Functional Programming in C++
Functional Programming in C++
 
GDSC NED Frontend Bootcamp Session 1.pptx
GDSC NED Frontend Bootcamp Session 1.pptxGDSC NED Frontend Bootcamp Session 1.pptx
GDSC NED Frontend Bootcamp Session 1.pptx
 
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
 

More from Dmitry Baranovskiy

JavaScript: enter the dragon
JavaScript: enter the dragonJavaScript: enter the dragon
JavaScript: enter the dragon
Dmitry Baranovskiy
 
The Origins of Magic
The Origins of MagicThe Origins of Magic
The Origins of Magic
Dmitry Baranovskiy
 
Demystifying Prototypes
Demystifying PrototypesDemystifying Prototypes
Demystifying Prototypes
Dmitry Baranovskiy
 
Raphaël
RaphaëlRaphaël
Type Recognition
Type RecognitionType Recognition
Type Recognition
Dmitry Baranovskiy
 
Raphaël JS Conf
Raphaël JS ConfRaphaël JS Conf
Raphaël JS Conf
Dmitry Baranovskiy
 
Your JavaScript Library
Your JavaScript LibraryYour JavaScript Library
Your JavaScript Library
Dmitry Baranovskiy
 
Canvas
CanvasCanvas
SVG
SVGSVG
Raphael
RaphaelRaphael
Web Vector Graphics
Web Vector GraphicsWeb Vector Graphics
Web Vector Graphics
Dmitry Baranovskiy
 
Typography on the Web
Typography on the WebTypography on the Web
Typography on the Web
Dmitry Baranovskiy
 
Microformats—the hidden treasure
Microformats—the hidden treasureMicroformats—the hidden treasure
Microformats—the hidden treasure
Dmitry Baranovskiy
 
Advanced JavaScript Techniques
Advanced JavaScript TechniquesAdvanced JavaScript Techniques
Advanced JavaScript Techniques
Dmitry Baranovskiy
 

More from Dmitry Baranovskiy (14)

JavaScript: enter the dragon
JavaScript: enter the dragonJavaScript: enter the dragon
JavaScript: enter the dragon
 
The Origins of Magic
The Origins of MagicThe Origins of Magic
The Origins of Magic
 
Demystifying Prototypes
Demystifying PrototypesDemystifying Prototypes
Demystifying Prototypes
 
Raphaël
RaphaëlRaphaël
Raphaël
 
Type Recognition
Type RecognitionType Recognition
Type Recognition
 
Raphaël JS Conf
Raphaël JS ConfRaphaël JS Conf
Raphaël JS Conf
 
Your JavaScript Library
Your JavaScript LibraryYour JavaScript Library
Your JavaScript Library
 
Canvas
CanvasCanvas
Canvas
 
SVG
SVGSVG
SVG
 
Raphael
RaphaelRaphael
Raphael
 
Web Vector Graphics
Web Vector GraphicsWeb Vector Graphics
Web Vector Graphics
 
Typography on the Web
Typography on the WebTypography on the Web
Typography on the Web
 
Microformats—the hidden treasure
Microformats—the hidden treasureMicroformats—the hidden treasure
Microformats—the hidden treasure
 
Advanced JavaScript Techniques
Advanced JavaScript TechniquesAdvanced JavaScript Techniques
Advanced JavaScript Techniques
 

Recently uploaded

inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham HillinQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
LizaNolte
 
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptxPRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
christinelarrosa
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin..."$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
Fwdays
 
Discover the Unseen: Tailored Recommendation of Unwatched Content
Discover the Unseen: Tailored Recommendation of Unwatched ContentDiscover the Unseen: Tailored Recommendation of Unwatched Content
Discover the Unseen: Tailored Recommendation of Unwatched Content
ScyllaDB
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
Ivo Velitchkov
 
Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!
Tobias Schneck
 
From Natural Language to Structured Solr Queries using LLMs
From Natural Language to Structured Solr Queries using LLMsFrom Natural Language to Structured Solr Queries using LLMs
From Natural Language to Structured Solr Queries using LLMs
Sease
 
"NATO Hackathon Winner: AI-Powered Drug Search", Taras Kloba
"NATO Hackathon Winner: AI-Powered Drug Search",  Taras Kloba"NATO Hackathon Winner: AI-Powered Drug Search",  Taras Kloba
"NATO Hackathon Winner: AI-Powered Drug Search", Taras Kloba
Fwdays
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
Jason Yip
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
DianaGray10
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
AI in the Workplace Reskilling, Upskilling, and Future Work.pptx
AI in the Workplace Reskilling, Upskilling, and Future Work.pptxAI in the Workplace Reskilling, Upskilling, and Future Work.pptx
AI in the Workplace Reskilling, Upskilling, and Future Work.pptx
Sunil Jagani
 
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
"Scaling RAG Applications to serve millions of users",  Kevin Goedecke"Scaling RAG Applications to serve millions of users",  Kevin Goedecke
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
Fwdays
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
Safe Software
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
Pablo Gómez Abajo
 
ScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking ReplicationScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking Replication
ScyllaDB
 

Recently uploaded (20)

inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham HillinQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
 
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptxPRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin..."$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
 
Discover the Unseen: Tailored Recommendation of Unwatched Content
Discover the Unseen: Tailored Recommendation of Unwatched ContentDiscover the Unseen: Tailored Recommendation of Unwatched Content
Discover the Unseen: Tailored Recommendation of Unwatched Content
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
 
Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!
 
From Natural Language to Structured Solr Queries using LLMs
From Natural Language to Structured Solr Queries using LLMsFrom Natural Language to Structured Solr Queries using LLMs
From Natural Language to Structured Solr Queries using LLMs
 
"NATO Hackathon Winner: AI-Powered Drug Search", Taras Kloba
"NATO Hackathon Winner: AI-Powered Drug Search",  Taras Kloba"NATO Hackathon Winner: AI-Powered Drug Search",  Taras Kloba
"NATO Hackathon Winner: AI-Powered Drug Search", Taras Kloba
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
AI in the Workplace Reskilling, Upskilling, and Future Work.pptx
AI in the Workplace Reskilling, Upskilling, and Future Work.pptxAI in the Workplace Reskilling, Upskilling, and Future Work.pptx
AI in the Workplace Reskilling, Upskilling, and Future Work.pptx
 
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
"Scaling RAG Applications to serve millions of users",  Kevin Goedecke"Scaling RAG Applications to serve millions of users",  Kevin Goedecke
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
 
ScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking ReplicationScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking Replication
 

Obvious Secrets of JavaScript

  • 1. obvious secrets of JavaScript Monday, 21 December 2009
  • 3. E very object (including host objects) must implement the e)) and ((Class)) propertie s and the ((Get)), ((Put)), ((Prototyp t)), ((HasProperty)), ((Dele te)), and ((DefaultValue)) ((CanPu . (Note, however, that the ((D efaultValue)) method may, methods exception.) The value for some objects , simply throw a TypeError Prototype)) property must be either an object or null, and of the (( Prototype)) chain must have finite length (that is, starting every (( y object, recursively access ing the ((Prototype)) property from an entually lead to a null val ue). Whether or not a native must ev an have a host object as its ((Prototype)) depends on the object c implementation. The value of the ((Class)) property is defined by this specification for every kind of built-i n object. The value of the ((Class)) prop erty of a host object may be any value , even a value used by Monday, 21 December 2009
  • 4. E very object (including host objects) must implement the e)) and ((Class)) propertie s and the ((Get)), ((Put)), ((Prototyp t)), ((HasProperty)), ((Dele te)), and ((DefaultValue)) ((CanPu . (Note, however, that the ((D efaultValue)) method may, methods exception.) The value for some objects , simply throw a TypeError Prototype)) property must be either an object or null, and of the (( Prototype)) chain must have finite length (that is, starting every (( ing the ((Prototype)) property from an It is a bit “cryptic” y object, recursively access entually lead to a null val ue). Whether or not a native must ev an have a host object as its ((Prototype)) depends on the object c implementation. The value of the ((Class)) property is defined by this specification for every kind of built-i n object. The value of the ((Class)) prop erty of a host object may be any value , even a value used by Monday, 21 December 2009
  • 6. number string boolean object null undefined Monday, 21 December 2009
  • 7. typeof undefined "undefined" null "object" number "number" boolean "boolean" string "string" object "object" Monday, 21 December 2009
  • 8. to Number undefined NaN null 0 number — boolean true→1, false→0 string parsing object .valueOf() Monday, 21 December 2009
  • 9. to String undefined "undefined" null "null" number "5" boolean "true" string — object .toString() Monday, 21 December 2009
  • 10. to Boolean undefined FALSE null FALSE number 0||NaN→false boolean — string ""→false object TRUE Monday, 21 December 2009
  • 11. to Object undefined exception! null exception! number new Number(5) boolean new Boolean(true) string new String("js") object object Monday, 21 December 2009
  • 12. 5 + 4 + "px" "$" + 1 + 2 "4" / "2" "$" + 1 - 2 "web".length typeof 5 typeof "5" typeof {key: value} typeof null typeof undefined typeof [1, 2, 3] typeof (4 - "px") +!{}[0] Monday, 21 December 2009
  • 13. 5 + 4 + "px" "9px" "$" + 1 + 2 "$12" "4" / "2" 2 "$" + 1 - 2 NaN "web".length 3 typeof 5 "number" typeof "5" "string" typeof {key: value} "object" typeof null "object" typeof undefined "undefined" typeof [1, 2, 3] "object" typeof (4 - "px") "number" +!{}[0] 1 Monday, 21 December 2009
  • 15. for in Monday, 21 December 2009
  • 16. var a = { x: 12, y: 23, r: 10, draw: function () {/*...*/} }; for (var property in a) { alert("a." + property + " = " + a[property]); } Monday, 21 December 2009
  • 17. var a = { x: 12, y: 23, r: 10, draw: function () {/*...*/} }; for (var property in a) { alert("a." + property + " = " + a[property]); } Monday, 21 December 2009
  • 18. ReadOnly DontEnum DontDelete Internal Monday, 21 December 2009
  • 20. var y = 1; function x() { var y = 2; return ++y; } var z = function () { return ++y; }; Monday, 21 December 2009
  • 21. function x() { var y = 2; return function () { return ++y; }; } var a = x(); a(); a(); Monday, 21 December 2009
  • 22. typeof function (){} == "function" Monday, 21 December 2009
  • 24. function add(a, b) { return a + b; } add(4, 5); // = 9 add(4, 5, 6, 7, 8, 9) // = 39 function add() { var sum = 0; for (var i = 0, ii = arguments.length; i < ii; i++) { sum +=+ arguments[i]; } return sum; } Monday, 21 December 2009
  • 25. Scope, Context & “this” Monday, 21 December 2009
  • 26. function is(it) { alert(this + " is " + it); } is("global"); is.call(5, "number"); is.apply("A", ["string"]); alert.is = is; alert.is("function"); Monday, 21 December 2009
  • 28. alert(b); 1 b = 1; alert(a); 2 var a = 1; (function () { 3 var x = 1; })(); alert(x); (function () { 4 y = 1; })(); alert(y); Monday, 21 December 2009
  • 30. function x(a) { 1 return a && x(--a); } var x = function (a) { 2 return a && x(--a); }; setTimeout(function (a) { 3 return a && arguments.callee(--a); }, 1000); var x = function y(a) { 4 return a && y(--a); }; setTimeout(function y(a) { 5 return a && y(--a); }, 1000); Monday, 21 December 2009
  • 32. var a = new Array; var a = new Array(3); var a = []; var a = [undefined, undefined, undefined]; var a = [1, 2, 3, 4]; Monday, 21 December 2009
  • 34. var a = new Object; var a = {}; var a = {x: 10, y: 15}; var a = { x: 10, name: "object", "font-style": "italic", getHeight: function () {/*...*/}, points: [1, 2, 3], child: {x: 10, y: 15} }; Monday, 21 December 2009
  • 36. Object Owns Prototype Monday, 21 December 2009
  • 37. var mouse = { 1 name: "Mike", voice: function () { alert("Squik!"); } }; var o = new Object; 2 o.name = "Mike"; o.voice = function () { alert("Squik!"); }; var O = function () { 3 this.name = "Mike"; this.voice = function () { alert("Squik!"); }; }; var o = new O; var O = function () {}; 4 O.prototype.name = "Mike"; O.prototype.voice = function () { alert("Squik!"); }; var o = new O; Monday, 21 December 2009
  • 40. Classic Model Class Object Class Object Object Object Monday, 21 December 2009
  • 41. Prototypal Model Object Object Object Object Monday, 21 December 2009
  • 42. var A = function () {}; 1 A Monday, 21 December 2009
  • 43. var A = function () {}; x: 5 A.prototype.x = 5; 1 A Monday, 21 December 2009
  • 44. var A = function () {}; x: 5 A.prototype.x = 5; var b = new A; 1 A b Monday, 21 December 2009
  • 45. x: 5 var A = function () {}; y: 6 A.prototype.x = 5; var b = new A; A.prototype.y = 6; 1 A b Monday, 21 December 2009
  • 46. x: 5 var A = function () {}; y: 6 A.prototype.x = 5; var b = new A; A.prototype.y = 6; 1 A var c = new A; b c Monday, 21 December 2009
  • 47. x: 5 var A = function () {}; y: 6 A.prototype.x = 5; var b = new A; A.prototype.y = 6; 1 A var c = new A; b.z = 7; b c z: 7 Monday, 21 December 2009
  • 48. x: 5 var A = function () {}; y: 6 A.prototype.x = 5; var b = new A; A.prototype.y = 6; 1 A var c = new A; b.z = 7; c.x = 4; b c z: 7 x: 4 Monday, 21 December 2009
  • 49. x: 5 w: 1 var A = function () {}; y: 6 u: 2 A.prototype.x = 5; var b = new A; A.prototype.y = 6; 1 A 2 var c = new A; b.z = 7; c.x = 4; A.prototype = { w: 1, u: 2 b c }; z: 7 x: 4 Monday, 21 December 2009
  • 50. x: 5 w: 1 var A = function () {}; y: 6 u: 2 A.prototype.x = 5; var b = new A; A.prototype.y = 6; 1 A 2 var c = new A; b.z = 7; c.x = 4; * A.prototype = { w: 1, u: 2 b c d }; var d = new A; z: 7 x: 4 — Monday, 21 December 2009
  • 51. x: 5 w: 1 var A = function () {}; y: 6 u: 2 A.prototype.x = 5; var b = new A; A.prototype.y = 6; 1 A 2 var c = new A; b.z = 7; c.x = 4; * A.prototype = { w: 1, u: 2 b c d }; var d = new A; z: 7 x: 4 — Monday, 21 December 2009
  • 52. Thank You Monday, 21 December 2009