SlideShare uma empresa Scribd logo
1 de 31
Baixar para ler offline
JavaScript for PHP
                           developers
                                   The Good Parts

                           Karsten Dambekalns <karsten@typo3.org>




Freitag, 15. Mai 2009
What this is about
                        the JavaScript language


                        not DOM
                        not browsers
                        not JS frameworks
                        not website building

Freitag, 15. Mai 2009
Am I qualified?

                        Probably not, when it comes to JS
                        Absolutely when it comes to PHP




Freitag, 15. Mai 2009
My JS background
                        First JS usage in the days of NN4
                        Used DynAPI, modified it
                        Saw alert() fix timing issues in browsers
                        Was happy when I did not have to use
                        JavaScript anymore
                        Thought I would never touch it again


Freitag, 15. Mai 2009
In JavaScript, there is
             a beautiful, elegant,
              highly expressive
                 language...

Freitag, 15. Mai 2009
...that is buried under
               a steaming pile of
             good intentions and
                    blunders.
                          Douglas Crockford


Freitag, 15. Mai 2009
Grammar


Freitag, 15. Mai 2009
Names
                        Names can be chosen freely
                        Some words are reserved, most of them not
                        used in JavaScript, though
                        Some word should have been reserved:
                          NaN, Infinity, undefined



Freitag, 15. Mai 2009
Numbers

                        Only one type, 64 bit floating point internally
                        Numbers have methods


                        (Most things in JavaScript are objects)



Freitag, 15. Mai 2009
Strings
                        16 bit Unicode, as such somewhat limited
                        Strings have methods and properties
                        toUpperCase(), length
                        Concatenation is done with +, as is addition

                        (Beware of errors as a result of this!)


Freitag, 15. Mai 2009
var
                        Most confusing for me was var – it seemed to
                        make no difference most of the time
                        Inside a function var defines a function’s
                        private variables
                        Otherwise variables will be globally accessible!



Freitag, 15. Mai 2009
Type issues
                        typeof returns a string with a type
                        For arrays and null it returns ‘object’
                        typeof NaN === ‘number’ // true!
                        undefined and NaN are global variables – you
                        can change their values



Freitag, 15. Mai 2009
Functions


Freitag, 15. Mai 2009
Basics

                        Functions are objects, they can be
                          stored in variables, arrays, objects
                          passed as arguments and returned
                        Functions can have methods (they are objects!)



Freitag, 15. Mai 2009
Defining functions
                        JavaScript has a function statement and a
                        function expression:
                         function foo() {}
                        means about the same as
                         var foo = function foo() {}
                        Remember: functions are values



Freitag, 15. Mai 2009
Closure
                        Inner functions can access parameters and
                        variables of the context in which they are
                        created
                        This can be used
                          to protect variables against manipulation
                          to keep values over function calls


Freitag, 15. Mai 2009
var myObject = function () {
                var value = 0;
                return {
                   increment: function (inc) {
                      value += typeof inc === ‘number ? inc : 1;
                   }
                   getValue: function () {
                      return value;
                   }
           }();


Freitag, 15. Mai 2009
Objects


Freitag, 15. Mai 2009
Basics
                        Numbers, strings, booleans, null, undefined are
                        simple types
                        Everything else is an object: arrays, functions,
                        regular expressions
                        Objects have properties with name and value
                        Objects are class free


Freitag, 15. Mai 2009
Object literals
                        Very cool way of creating objects, confusing if
                        seen for the first time (no new?!)
                        var flight = {
                          airline: ‘FLOW Flights’,
                          number: 3,
                          captain: { ... }
                        }


Freitag, 15. Mai 2009
The new statement
                        new creates an object that inherits from the
                        operand, then calls the operand with the
                        created object bound to this
                        If the operand customizes the object but you
                        forgot new, you change global variables!
                        If you use new, make constructor method
                        names UpperCamelCase


Freitag, 15. Mai 2009
Inheritance
                        Objects inherit from objects, no classes
                        Prototypal inheritence allows to augment
                        existing objects during runtime:
                         Foo.prototype.bar = function () { ... }
                        Even built-in objects can be enhanced
                        Local properties hide inherited ones


Freitag, 15. Mai 2009
Arrays


Freitag, 15. Mai 2009
Basics
                        Arrays can be created with array literals:
                         var data = [‘one’, ‘two’, ‘three’];
                        The length property of an array
                          is the largest integer property name +1
                          can be set and thus cut off arrays at the end



Freitag, 15. Mai 2009
Array or Object?
                        Simple rule for what to use:
                        When property names are small sequential
                        integers, use an array. Otherwise an object.
                        Hard to find out what you have:
                        You need to define a useful is_array method
                        yourself.



Freitag, 15. Mai 2009
Awful & bad parts


Freitag, 15. Mai 2009
Semicolon inerstion
                        JavaScript tries to fix programs by inserting
                        semicolons – do not rely on that!
                        What does this return?
                        return
                        {
                          status: true
                        };


Freitag, 15. Mai 2009
parseInt

                        parseInt(’16’) == parseInt(’16 tons’) == 16
                        parseInt(’08’) returns 0 because it assumes
                        octal numbers
                        Always provide the radix parameter to parseInt




Freitag, 15. Mai 2009
Bitwise operators

                        Avoid them if you think you gain speed
                        All numbers are floating point, so bitwise
                        operators convert to integer and back




Freitag, 15. Mai 2009
Read this!
               JavaScript: The Good Parts
                   Douglas Crockford
                        O’Reilly




Freitag, 15. Mai 2009
Thanks!


Freitag, 15. Mai 2009

Mais conteúdo relacionado

Destaque

13 facial neuropathology
13 facial neuropathology13 facial neuropathology
13 facial neuropathology
Ephrem Tamiru
 
B Cell Development
B Cell DevelopmentB Cell Development
B Cell Development
raj kumar
 
8. Acute Lymphoblastic Leukemia
8. Acute Lymphoblastic Leukemia8. Acute Lymphoblastic Leukemia
8. Acute Lymphoblastic Leukemia
Whiteraven68
 
Acute lymphoid leukemia (case presentation)
Acute lymphoid leukemia (case presentation)Acute lymphoid leukemia (case presentation)
Acute lymphoid leukemia (case presentation)
Dhritiman Chakrabarti
 
Social Media for Chicago Community Trust presentation
Social Media for Chicago Community Trust presentationSocial Media for Chicago Community Trust presentation
Social Media for Chicago Community Trust presentation
Hack the Hood
 
2.2 My Works About Use Case Analysis, Flowchart
2.2 My Works About Use Case Analysis, Flowchart2.2 My Works About Use Case Analysis, Flowchart
2.2 My Works About Use Case Analysis, Flowchart
Ruby Kuo
 
Visual studio tools 4 SharePoint SharePoint Saturday Arabia
Visual studio tools 4 SharePoint SharePoint Saturday ArabiaVisual studio tools 4 SharePoint SharePoint Saturday Arabia
Visual studio tools 4 SharePoint SharePoint Saturday Arabia
Marwan Tarek
 

Destaque (20)

pathology practical original slide NO2
pathology practical original slide NO2pathology practical original slide NO2
pathology practical original slide NO2
 
NEUROPATHOLOGY LECTURE 2009*
NEUROPATHOLOGY LECTURE 2009*NEUROPATHOLOGY LECTURE 2009*
NEUROPATHOLOGY LECTURE 2009*
 
pathology practical original slide NO1
pathology practical original slide NO1pathology practical original slide NO1
pathology practical original slide NO1
 
13 facial neuropathology
13 facial neuropathology13 facial neuropathology
13 facial neuropathology
 
B cell lymphoma
B cell lymphomaB cell lymphoma
B cell lymphoma
 
B Cell Development
B Cell DevelopmentB Cell Development
B Cell Development
 
8. Acute Lymphoblastic Leukemia
8. Acute Lymphoblastic Leukemia8. Acute Lymphoblastic Leukemia
8. Acute Lymphoblastic Leukemia
 
Acute lymphoid leukemia (case presentation)
Acute lymphoid leukemia (case presentation)Acute lymphoid leukemia (case presentation)
Acute lymphoid leukemia (case presentation)
 
Social Media for Chicago Community Trust presentation
Social Media for Chicago Community Trust presentationSocial Media for Chicago Community Trust presentation
Social Media for Chicago Community Trust presentation
 
Project execution for paranoids
Project execution for paranoidsProject execution for paranoids
Project execution for paranoids
 
2.2 My Works About Use Case Analysis, Flowchart
2.2 My Works About Use Case Analysis, Flowchart2.2 My Works About Use Case Analysis, Flowchart
2.2 My Works About Use Case Analysis, Flowchart
 
Formacion en entorno presencial y virtual
Formacion en entorno presencial y virtualFormacion en entorno presencial y virtual
Formacion en entorno presencial y virtual
 
State of Plone Caching
State of Plone CachingState of Plone Caching
State of Plone Caching
 
Task 1
Task 1Task 1
Task 1
 
03 - Le Rôle des Universités / The Role of Universities
03 - Le Rôle des Universités / The Role of Universities03 - Le Rôle des Universités / The Role of Universities
03 - Le Rôle des Universités / The Role of Universities
 
1001 Ona Career Day Preso
1001 Ona Career Day Preso1001 Ona Career Day Preso
1001 Ona Career Day Preso
 
Lvw Model Kids
Lvw Model   KidsLvw Model   Kids
Lvw Model Kids
 
Visual studio tools 4 SharePoint SharePoint Saturday Arabia
Visual studio tools 4 SharePoint SharePoint Saturday ArabiaVisual studio tools 4 SharePoint SharePoint Saturday Arabia
Visual studio tools 4 SharePoint SharePoint Saturday Arabia
 
A Kaleidoscopic Analysis of the Sing Up Project [clip]
A Kaleidoscopic Analysis of the Sing Up Project [clip]A Kaleidoscopic Analysis of the Sing Up Project [clip]
A Kaleidoscopic Analysis of the Sing Up Project [clip]
 
Digital Marketing e Mobile Marketing
Digital Marketing e Mobile MarketingDigital Marketing e Mobile Marketing
Digital Marketing e Mobile Marketing
 

Semelhante a JavaScript for PHP Developers

Your java script library
Your java script libraryYour java script library
Your java script library
jasfog
 

Semelhante a JavaScript for PHP Developers (12)

JSUG - ActionScript 3 vs Java by Christoph Pickl
JSUG - ActionScript 3 vs Java by Christoph PicklJSUG - ActionScript 3 vs Java by Christoph Pickl
JSUG - ActionScript 3 vs Java by Christoph Pickl
 
JSUG - AS3 vs Java by Christoph Pickl
JSUG - AS3 vs Java by Christoph PicklJSUG - AS3 vs Java by Christoph Pickl
JSUG - AS3 vs Java by Christoph Pickl
 
Clean Code
Clean CodeClean Code
Clean Code
 
Functional Java Script - Webtechcon 2009
Functional Java Script - Webtechcon 2009Functional Java Script - Webtechcon 2009
Functional Java Script - Webtechcon 2009
 
MacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meetMacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meet
 
Groovy
GroovyGroovy
Groovy
 
Building A Framework On Rack
Building A Framework On RackBuilding A Framework On Rack
Building A Framework On Rack
 
Chad Udell - Developers are from Mars, Designers are from Venus
Chad Udell - Developers are from Mars, Designers are from VenusChad Udell - Developers are from Mars, Designers are from Venus
Chad Udell - Developers are from Mars, Designers are from Venus
 
Treetop - I'd rather have one problem
Treetop - I'd rather have one problemTreetop - I'd rather have one problem
Treetop - I'd rather have one problem
 
Your java script library
Your java script libraryYour java script library
Your java script library
 
Objective-C A Beginner's Dive (with notes)
Objective-C A Beginner's Dive (with notes)Objective-C A Beginner's Dive (with notes)
Objective-C A Beginner's Dive (with notes)
 
Lecture 03
Lecture 03Lecture 03
Lecture 03
 

Mais de Karsten Dambekalns

The agile future of a ponderous project
The agile future of a ponderous projectThe agile future of a ponderous project
The agile future of a ponderous project
Karsten Dambekalns
 
How Domain-Driven Design helps you to migrate into the future
How Domain-Driven Design helps you to migrate into the futureHow Domain-Driven Design helps you to migrate into the future
How Domain-Driven Design helps you to migrate into the future
Karsten Dambekalns
 
Content Repository, Versioning and Workspaces in TYPO3 Phoenix
Content Repository, Versioning and Workspaces in TYPO3 PhoenixContent Repository, Versioning and Workspaces in TYPO3 Phoenix
Content Repository, Versioning and Workspaces in TYPO3 Phoenix
Karsten Dambekalns
 

Mais de Karsten Dambekalns (20)

The Perfect Neos Project Setup
The Perfect Neos Project SetupThe Perfect Neos Project Setup
The Perfect Neos Project Setup
 
Sawubona! Content Dimensions with Neos
Sawubona! Content Dimensions with NeosSawubona! Content Dimensions with Neos
Sawubona! Content Dimensions with Neos
 
Deploying TYPO3 Neos websites using Surf
Deploying TYPO3 Neos websites using SurfDeploying TYPO3 Neos websites using Surf
Deploying TYPO3 Neos websites using Surf
 
Profiling TYPO3 Flow Applications
Profiling TYPO3 Flow ApplicationsProfiling TYPO3 Flow Applications
Profiling TYPO3 Flow Applications
 
Using Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowUsing Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 Flow
 
i18n and L10n in TYPO3 Flow
i18n and L10n in TYPO3 Flowi18n and L10n in TYPO3 Flow
i18n and L10n in TYPO3 Flow
 
FLOW3-Workshop F3X12
FLOW3-Workshop F3X12FLOW3-Workshop F3X12
FLOW3-Workshop F3X12
 
Doctrine in FLOW3
Doctrine in FLOW3Doctrine in FLOW3
Doctrine in FLOW3
 
How Git and Gerrit make you more productive
How Git and Gerrit make you more productiveHow Git and Gerrit make you more productive
How Git and Gerrit make you more productive
 
The agile future of a ponderous project
The agile future of a ponderous projectThe agile future of a ponderous project
The agile future of a ponderous project
 
How Domain-Driven Design helps you to migrate into the future
How Domain-Driven Design helps you to migrate into the futureHow Domain-Driven Design helps you to migrate into the future
How Domain-Driven Design helps you to migrate into the future
 
Content Repository, Versioning and Workspaces in TYPO3 Phoenix
Content Repository, Versioning and Workspaces in TYPO3 PhoenixContent Repository, Versioning and Workspaces in TYPO3 Phoenix
Content Repository, Versioning and Workspaces in TYPO3 Phoenix
 
Transparent Object Persistence (within FLOW3)
Transparent Object Persistence (within FLOW3)Transparent Object Persistence (within FLOW3)
Transparent Object Persistence (within FLOW3)
 
Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3
 
Implementing a JSR-283 Content Repository in PHP
Implementing a JSR-283 Content Repository in PHPImplementing a JSR-283 Content Repository in PHP
Implementing a JSR-283 Content Repository in PHP
 
Knowledge Management in der TYPO3 Community
Knowledge Management in der TYPO3 CommunityKnowledge Management in der TYPO3 Community
Knowledge Management in der TYPO3 Community
 
Unicode & PHP6
Unicode & PHP6Unicode & PHP6
Unicode & PHP6
 
Implementing a JSR-283 Content Repository in PHP
Implementing a JSR-283 Content Repository in PHPImplementing a JSR-283 Content Repository in PHP
Implementing a JSR-283 Content Repository in PHP
 
A Content Repository for TYPO3 5.0
A Content Repository for TYPO3 5.0A Content Repository for TYPO3 5.0
A Content Repository for TYPO3 5.0
 
Introduction to Source Code Management
Introduction to Source Code ManagementIntroduction to Source Code Management
Introduction to Source Code Management
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
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
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

JavaScript for PHP Developers

  • 1. JavaScript for PHP developers The Good Parts Karsten Dambekalns <karsten@typo3.org> Freitag, 15. Mai 2009
  • 2. What this is about the JavaScript language not DOM not browsers not JS frameworks not website building Freitag, 15. Mai 2009
  • 3. Am I qualified? Probably not, when it comes to JS Absolutely when it comes to PHP Freitag, 15. Mai 2009
  • 4. My JS background First JS usage in the days of NN4 Used DynAPI, modified it Saw alert() fix timing issues in browsers Was happy when I did not have to use JavaScript anymore Thought I would never touch it again Freitag, 15. Mai 2009
  • 5. In JavaScript, there is a beautiful, elegant, highly expressive language... Freitag, 15. Mai 2009
  • 6. ...that is buried under a steaming pile of good intentions and blunders. Douglas Crockford Freitag, 15. Mai 2009
  • 8. Names Names can be chosen freely Some words are reserved, most of them not used in JavaScript, though Some word should have been reserved: NaN, Infinity, undefined Freitag, 15. Mai 2009
  • 9. Numbers Only one type, 64 bit floating point internally Numbers have methods (Most things in JavaScript are objects) Freitag, 15. Mai 2009
  • 10. Strings 16 bit Unicode, as such somewhat limited Strings have methods and properties toUpperCase(), length Concatenation is done with +, as is addition (Beware of errors as a result of this!) Freitag, 15. Mai 2009
  • 11. var Most confusing for me was var – it seemed to make no difference most of the time Inside a function var defines a function’s private variables Otherwise variables will be globally accessible! Freitag, 15. Mai 2009
  • 12. Type issues typeof returns a string with a type For arrays and null it returns ‘object’ typeof NaN === ‘number’ // true! undefined and NaN are global variables – you can change their values Freitag, 15. Mai 2009
  • 14. Basics Functions are objects, they can be stored in variables, arrays, objects passed as arguments and returned Functions can have methods (they are objects!) Freitag, 15. Mai 2009
  • 15. Defining functions JavaScript has a function statement and a function expression: function foo() {} means about the same as var foo = function foo() {} Remember: functions are values Freitag, 15. Mai 2009
  • 16. Closure Inner functions can access parameters and variables of the context in which they are created This can be used to protect variables against manipulation to keep values over function calls Freitag, 15. Mai 2009
  • 17. var myObject = function () { var value = 0; return { increment: function (inc) { value += typeof inc === ‘number ? inc : 1; } getValue: function () { return value; } }(); Freitag, 15. Mai 2009
  • 19. Basics Numbers, strings, booleans, null, undefined are simple types Everything else is an object: arrays, functions, regular expressions Objects have properties with name and value Objects are class free Freitag, 15. Mai 2009
  • 20. Object literals Very cool way of creating objects, confusing if seen for the first time (no new?!) var flight = { airline: ‘FLOW Flights’, number: 3, captain: { ... } } Freitag, 15. Mai 2009
  • 21. The new statement new creates an object that inherits from the operand, then calls the operand with the created object bound to this If the operand customizes the object but you forgot new, you change global variables! If you use new, make constructor method names UpperCamelCase Freitag, 15. Mai 2009
  • 22. Inheritance Objects inherit from objects, no classes Prototypal inheritence allows to augment existing objects during runtime: Foo.prototype.bar = function () { ... } Even built-in objects can be enhanced Local properties hide inherited ones Freitag, 15. Mai 2009
  • 24. Basics Arrays can be created with array literals: var data = [‘one’, ‘two’, ‘three’]; The length property of an array is the largest integer property name +1 can be set and thus cut off arrays at the end Freitag, 15. Mai 2009
  • 25. Array or Object? Simple rule for what to use: When property names are small sequential integers, use an array. Otherwise an object. Hard to find out what you have: You need to define a useful is_array method yourself. Freitag, 15. Mai 2009
  • 26. Awful & bad parts Freitag, 15. Mai 2009
  • 27. Semicolon inerstion JavaScript tries to fix programs by inserting semicolons – do not rely on that! What does this return? return { status: true }; Freitag, 15. Mai 2009
  • 28. parseInt parseInt(’16’) == parseInt(’16 tons’) == 16 parseInt(’08’) returns 0 because it assumes octal numbers Always provide the radix parameter to parseInt Freitag, 15. Mai 2009
  • 29. Bitwise operators Avoid them if you think you gain speed All numbers are floating point, so bitwise operators convert to integer and back Freitag, 15. Mai 2009
  • 30. Read this! JavaScript: The Good Parts Douglas Crockford O’Reilly Freitag, 15. Mai 2009