SlideShare a Scribd company logo
JavaScript 1.8.5
New Features Explored
by Milan Adamovsky
http://milan.adamovsky.com ◆ http://www.hardcorejs.com
Friday, October 4, 13
What it is
• Culmination of good-to-haves
• Most features can be shimmed
• Supported by all mobile devices
• Supported by most modern browsers
• IE8 is still in heavy use (JavaScript 1.5)
Friday, October 4, 13
Remember
• Includes many features introduced since 1.5
• 1.6
• 1.7 features mainly supported in FireFox
• Use reference material for all versions
• Some features are deprecated
Friday, October 4, 13
What to know
• Array functions
• Object properties
• Still doesn’t have block scope
• Function features
• “use strict”
Friday, October 4, 13
Quick notes
• NaN, Infinity, and undefined immutable
• No trailing commas in JSON.parse()
• Supports “strict mode”
• apply() accepts array-like object
• Data properties are big
Friday, October 4, 13
Strings
Friday, October 4, 13
“”.trim()
• Introduced in 1.8.5
• Removes leading spaces
• Removes trailing spaces
• Works on strings
Friday, October 4, 13
Example
" Hello World ! ".trim();
"Hello World !"
Friday, October 4, 13
Arrays
Friday, October 4, 13
[].map(fn, this)
• Introduced in 1.6
• Does not mutate array
• Works only on indexes with values
• Executes fn on each item in array
• Modify an array’s items without a loop
Friday, October 4, 13
Example
function resolve(item)
{
return $(item);
}
var selectors = ["body", "#hello"].map(resolve);
console.log(selectors);
[ e.fn.init[1], e.fn.init[0] ]
Friday, October 4, 13
[].reduce(fn, first)
• Introduced in 1.8
• Does not mutate array
• Executes fn on each item of array
• Reduce array to one value without loops
• Also available .reduceRight()
Friday, October 4, 13
Example
function callback(previousItem, currentItem, index, array)
{
console.log(previousItem, " - ", currentItem, " - ", index, " - ", array);
return previousItem + " " + currentItem;
}
var sentence = ["three", "little", "pigs", "red", "riding", "hood"].reduce(callback);
three - little - 1 - ["three", "little", "pigs", "red", "riding", "hood"]
three little - pigs - 2 - ["three", "little", "pigs", "red", "riding", "hood"]
three little pigs - red - 3 - ["three", "little", "pigs", "red", "riding", "hood"]
three little pigs red - riding - 4 - ["three", "little", "pigs", "red", "riding", "hood"]
three little pigs red riding - hood - 5 - ["three", "little", "pigs", "red", "riding", "hood"]
Friday, October 4, 13
Array.isArray(obj)
• Introduced in 1.8.5
• Determine if object is truly an array
• Fastest performance
• Prototype is an array
• Arguments are not an array
Friday, October 4, 13
Example
function callback(switcher)
{
return switcher
? ["m", "t", "w", "t", "f"]
: undefined;
}
Array.isArray([]);
Array.isArray(new Array());
Array.isArray(callback(true));
Array.isArray(callback(false));
true
true
true
false
Friday, October 4, 13
[].filter(fn, this)
• Introduced in 1.6
• Filters an array via fn
• Returns all items for which fn returns true
• Doesn’t need loops
• Takes optional parameter for this
Friday, October 4, 13
Example
function callback(value, index, array)
{
return value.days === 31;
}
[
{ days : 31, month : "January" },
{ days : 28, month : "February" },
{ days : 31, month : "March" },
{ days : 30, month : "April" },
{ days : 31, month : "May" }
].filter(callback);
[ Object, Object, Object ]
Friday, October 4, 13
See also
• [].forEach(fn, this)
• [].toString()
• [].some(fn, this)
• [].every(fn, this)
• [].lastIndexOf(search, index)
Friday, October 4, 13
Objects
Friday, October 4, 13
Property descriptors
• Meta data describing object
• Each property has descriptor
• Data descriptors
• Accessor descriptors
• Cannot mix both
Friday, October 4, 13
Data descriptor
• Introduced in 1.8.5
• Default descriptor type
• Define configuration of property values
• Optional key value (defaults to undefined)
• Optional key writeable (defaults to false)
Friday, October 4, 13
Example
var person = {};
Object.defineProperty(person,
"firstName",
{
configurable : true,
enumerable : true,
value : "Joe",
writable : true
});
console.log(person.firstName);
person.firstName = "Jane";
console.log(person.firstName);
Joe
Jane
Friday, October 4, 13
Example
var person = {};
Object.defineProperty(person,
"firstName",
{
configurable : true,
enumerable : true,
value : "Joe",
writable : false
});
console.log(person.firstName);
person.firstName = "Jane";
console.log(person.firstName);
Joe
Joe
Friday, October 4, 13
Default values
• Default values apply with defineProperty()
• Object literal assignment defaults to truely
• Defaults to falsely with defineProperty()
• All descriptors have writable attribute
• All descriptors have enumerable attribute
Friday, October 4, 13
Accessor descriptor
• Introduced in 1.8.5
• Bind functionality with property
• Define configuration of property values
• Optional key value (defaults to undefined)
• Optional key writeable (defaults to false)
Friday, October 4, 13
Example
var year = {};
(function ()
{
var month = "";
Object.defineProperty(year,
"month",
{
configurable : true,
enumerable : true,
get : function ()
{
return month;
},
set : function (value)
{
value = value.toLowerCase().substr(0, 3);
month = ([ "jan", "feb", "mar" ].filter(function (val, index, arr)
{
return value === val;
}))[0];
}
});
})();
year.month = "February";
console.log(year.month);
Friday, October 4, 13
Notice
• Value needs to live outside the setter
• Closure is needed to protect value
• Keyword let is non-standard
• Use a getter to retrieve value
• Logic can exist in both getter and setter
Friday, October 4, 13
Important
• Properties are basis for most new features
• defineProperty() defines one property
• defineProperties() defines many at once
Friday, October 4, 13
Read descriptors
• Use Object.getOwnPropertyDescriptor(o, prop)
• Returns a property descriptor object
• Object contains all descriptor attributes
• Returns undefined if invalid property
• Object is a normal object literal
Friday, October 4, 13
Example
var person = {};
Object.defineProperty(person,
"firstName",
{
configurable : false,
enumerable : true,
value : "Joe"
});
console.log(Object.getOwnPropertyDescriptor(person, "firstName"));
Object {value: "Joe", writable: false, enumerable: true, configurable: false}
Friday, October 4, 13
Object.keys(obj)
• Returns array of properties
• Only its own enumerable properties
• Also works on arrays
• Does not travel prototype chain
Friday, October 4, 13
Example
var person = {
"age" : 99,
"lastName" : "Shmo"
};
Object.defineProperty(person,
"firstName",
{
configurable : true,
enumerable : false,
value : "Joe",
writable : true
});
console.log(Object.keys(person));
["age", "lastName"]
Friday, October 4, 13
See also
• for...in to list all properties
• Object.getOwnPropertyNames(obj)
Friday, October 4, 13
Object.seal(obj)
• Partially locks down object
• Locks descriptors from being removed
• Locks object from new properties
• Properties can still be writable
• Prototype chain remains uneffected
Friday, October 4, 13
Example
var person = {
"age" : 99,
"lastName" : "Shmo"
};
Object.defineProperty(person,
"firstName",
{
configurable : true,
enumerable : false,
value : "Joe",
writable : true
});
console.log(Object.keys(person));
["age", "lastName"]
Friday, October 4, 13
.preventExtensions(obj)
• Prevents own properties from being added
• Properties can still be removed
• Does not lock down prototype
Friday, October 4, 13
Object.freeze(obj)
• Complete shallow lock-down of object
• Locks descriptors from being removed
• Locks object from new properties
• Locks properties from being modified
• A frozen object gives you most security
Friday, October 4, 13
Check state
• Use isSealed() to check for seal
• Use isExtensible() to check extensibility
• Use isFrozen() to check for freeze
• States can only change to be tighter
• Cannot unfreeze
Friday, October 4, 13
Functions
Friday, October 4, 13
function(){}.bind()
• Marry a context to function definition
• Similar to call() and apply()
• Does not execute function
• Can also marry arguments to function
• Called a bound function
Friday, October 4, 13
Example
function sample()
{
console.log(this);
}
var boundFunction;
sample();
boundFunction = sample.bind({ "first" : "Joe" } );
boundFunction();
sample();
(sample.bind({ "last" : "Shmo" } ))();
Window {top: Window, window: Window, location: Location, external: Object, chrome: Object…}
Object {first: "Joe"}
Window {top: Window, window: Window, location: Location, external: Object, chrome: Object…}
Object {last: "Shmo"}
Friday, October 4, 13
Connect
• Thank you for your time
• Connect with me on LinkedIn
• Join the Hardcore JavaScript community
• Read my blog
• Contact me via e-mail
Friday, October 4, 13

More Related Content

What's hot

Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Charles Nutter
 
Introduce Django
Introduce DjangoIntroduce Django
Introduce Django
Chui-Wen Chiu
 
Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast Lane
Andres Almiray
 
Javascript the New Parts
Javascript the New PartsJavascript the New Parts
Javascript the New Parts
Federico Galassi
 
Objective-c memory
Objective-c memoryObjective-c memory
Objective-c memory
Anton Krokhmalyuk
 
Gcrc talk
Gcrc talkGcrc talk
Gcrc talk
Tejas Dinkar
 
Monads asking the right question
Monads  asking the right questionMonads  asking the right question
Monads asking the right question
Pawel Szulc
 
Go Java, Go!
Go Java, Go!Go Java, Go!
Go Java, Go!
Andres Almiray
 
Painless Persistence with Realm
Painless Persistence with RealmPainless Persistence with Realm
Painless Persistence with Realm
Christian Melchior
 
Dynamic Python
Dynamic PythonDynamic Python
Dynamic Python
Chui-Wen Chiu
 
Swift와 Objective-C를 함께 쓰는 방법
Swift와 Objective-C를 함께 쓰는 방법Swift와 Objective-C를 함께 쓰는 방법
Swift와 Objective-C를 함께 쓰는 방법
Jung Kim
 
Understanding Prototypal Inheritance
Understanding Prototypal InheritanceUnderstanding Prototypal Inheritance
Understanding Prototypal Inheritance
Guy Royse
 
iSoligorsk #3 2013
iSoligorsk #3 2013iSoligorsk #3 2013
iSoligorsk #3 2013
Friedrich Boeckh
 
Sustainable TDD
Sustainable TDDSustainable TDD
Sustainable TDD
Steven Mak
 
7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in Kotlin7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in Kotlin
Luca Guadagnini
 
Modernizes your objective C - Oliviero
Modernizes your objective C - OlivieroModernizes your objective C - Oliviero
Modernizes your objective C - Oliviero
Codemotion
 
Gettingintotheloop 100123225021-phpapp01
Gettingintotheloop 100123225021-phpapp01Gettingintotheloop 100123225021-phpapp01
Gettingintotheloop 100123225021-phpapp01
Ravi Kumar
 
Meet Couch DB
Meet Couch DBMeet Couch DB
Meet Couch DB
estialvarez
 
JavaScript Primer
JavaScript PrimerJavaScript Primer
JavaScript Primer
Daniel Cousineau
 
JS Level Up: Prototypes
JS Level Up: PrototypesJS Level Up: Prototypes
JS Level Up: Prototypes
Vernon Kesner
 

What's hot (20)

Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
 
Introduce Django
Introduce DjangoIntroduce Django
Introduce Django
 
Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast Lane
 
Javascript the New Parts
Javascript the New PartsJavascript the New Parts
Javascript the New Parts
 
Objective-c memory
Objective-c memoryObjective-c memory
Objective-c memory
 
Gcrc talk
Gcrc talkGcrc talk
Gcrc talk
 
Monads asking the right question
Monads  asking the right questionMonads  asking the right question
Monads asking the right question
 
Go Java, Go!
Go Java, Go!Go Java, Go!
Go Java, Go!
 
Painless Persistence with Realm
Painless Persistence with RealmPainless Persistence with Realm
Painless Persistence with Realm
 
Dynamic Python
Dynamic PythonDynamic Python
Dynamic Python
 
Swift와 Objective-C를 함께 쓰는 방법
Swift와 Objective-C를 함께 쓰는 방법Swift와 Objective-C를 함께 쓰는 방법
Swift와 Objective-C를 함께 쓰는 방법
 
Understanding Prototypal Inheritance
Understanding Prototypal InheritanceUnderstanding Prototypal Inheritance
Understanding Prototypal Inheritance
 
iSoligorsk #3 2013
iSoligorsk #3 2013iSoligorsk #3 2013
iSoligorsk #3 2013
 
Sustainable TDD
Sustainable TDDSustainable TDD
Sustainable TDD
 
7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in Kotlin7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in Kotlin
 
Modernizes your objective C - Oliviero
Modernizes your objective C - OlivieroModernizes your objective C - Oliviero
Modernizes your objective C - Oliviero
 
Gettingintotheloop 100123225021-phpapp01
Gettingintotheloop 100123225021-phpapp01Gettingintotheloop 100123225021-phpapp01
Gettingintotheloop 100123225021-phpapp01
 
Meet Couch DB
Meet Couch DBMeet Couch DB
Meet Couch DB
 
JavaScript Primer
JavaScript PrimerJavaScript Primer
JavaScript Primer
 
JS Level Up: Prototypes
JS Level Up: PrototypesJS Level Up: Prototypes
JS Level Up: Prototypes
 

Similar to JavaScript 1.8.5: New Features Explored

Javascript the Interlingua of the Web
Javascript the Interlingua of the WebJavascript the Interlingua of the Web
Javascript the Interlingua of the Web
andersjanmyr
 
Enterprise javascriptsession3
Enterprise javascriptsession3Enterprise javascriptsession3
Enterprise javascriptsession3
Troy Miles
 
The Not Java That's Not Scala
The Not Java That's Not ScalaThe Not Java That's Not Scala
The Not Java That's Not Scala
Justin Lee
 
Javascript the Language of the Web
Javascript the Language of the WebJavascript the Language of the Web
Javascript the Language of the Web
andersjanmyr
 
Intro to pattern matching in scala
Intro to pattern matching in scalaIntro to pattern matching in scala
Intro to pattern matching in scala
Jan Krag
 
Everything is Permitted: Extending Built-ins
Everything is Permitted: Extending Built-insEverything is Permitted: Extending Built-ins
Everything is Permitted: Extending Built-ins
Andrew Dupont
 
Object Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptObject Oriented Programming in JavaScript
Object Oriented Programming in JavaScript
zand3rs
 
Lessons from 4 years of driver develoment
Lessons from 4 years of driver develomentLessons from 4 years of driver develoment
Lessons from 4 years of driver develoment
christkv
 
Property based Testing - generative data & executable domain rules
Property based Testing - generative data & executable domain rulesProperty based Testing - generative data & executable domain rules
Property based Testing - generative data & executable domain rules
Debasish Ghosh
 
The Shape of Functional Programming
The Shape of Functional ProgrammingThe Shape of Functional Programming
The Shape of Functional Programming
Mike Fogus
 
Scala 101-bcndevcon
Scala 101-bcndevconScala 101-bcndevcon
Scala 101-bcndevcon
Ignasi Marimon-Clos i Sunyol
 
Awesomeness of JavaScript…almost
Awesomeness of JavaScript…almostAwesomeness of JavaScript…almost
Awesomeness of JavaScript…almost
Quinton Sheppard
 
Basic Javascript
Basic JavascriptBasic Javascript
Basic Javascript
Bunlong Van
 
Expressjs basic to advance, power by Node.js
Expressjs basic to advance, power by Node.jsExpressjs basic to advance, power by Node.js
Expressjs basic to advance, power by Node.js
Caesar Chi
 
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
 
JSConf: All You Can Leet
JSConf: All You Can LeetJSConf: All You Can Leet
JSConf: All You Can Leet
johndaviddalton
 
Spock: Test Well and Prosper
Spock: Test Well and ProsperSpock: Test Well and Prosper
Spock: Test Well and Prosper
Ken Kousen
 
Gl qtp day 3 2
Gl qtp day 3   2Gl qtp day 3   2
Gl qtp day 3 2
Pragya Rastogi
 
Teach your kids how to program with Python and the Raspberry Pi
Teach your kids how to program with Python and the Raspberry PiTeach your kids how to program with Python and the Raspberry Pi
Teach your kids how to program with Python and the Raspberry Pi
Juan Gomez
 
Mastering ElasticSearch with Ruby and Tire
Mastering ElasticSearch with Ruby and TireMastering ElasticSearch with Ruby and Tire
Mastering ElasticSearch with Ruby and Tire
Luca Bonmassar
 

Similar to JavaScript 1.8.5: New Features Explored (20)

Javascript the Interlingua of the Web
Javascript the Interlingua of the WebJavascript the Interlingua of the Web
Javascript the Interlingua of the Web
 
Enterprise javascriptsession3
Enterprise javascriptsession3Enterprise javascriptsession3
Enterprise javascriptsession3
 
The Not Java That's Not Scala
The Not Java That's Not ScalaThe Not Java That's Not Scala
The Not Java That's Not Scala
 
Javascript the Language of the Web
Javascript the Language of the WebJavascript the Language of the Web
Javascript the Language of the Web
 
Intro to pattern matching in scala
Intro to pattern matching in scalaIntro to pattern matching in scala
Intro to pattern matching in scala
 
Everything is Permitted: Extending Built-ins
Everything is Permitted: Extending Built-insEverything is Permitted: Extending Built-ins
Everything is Permitted: Extending Built-ins
 
Object Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptObject Oriented Programming in JavaScript
Object Oriented Programming in JavaScript
 
Lessons from 4 years of driver develoment
Lessons from 4 years of driver develomentLessons from 4 years of driver develoment
Lessons from 4 years of driver develoment
 
Property based Testing - generative data & executable domain rules
Property based Testing - generative data & executable domain rulesProperty based Testing - generative data & executable domain rules
Property based Testing - generative data & executable domain rules
 
The Shape of Functional Programming
The Shape of Functional ProgrammingThe Shape of Functional Programming
The Shape of Functional Programming
 
Scala 101-bcndevcon
Scala 101-bcndevconScala 101-bcndevcon
Scala 101-bcndevcon
 
Awesomeness of JavaScript…almost
Awesomeness of JavaScript…almostAwesomeness of JavaScript…almost
Awesomeness of JavaScript…almost
 
Basic Javascript
Basic JavascriptBasic Javascript
Basic Javascript
 
Expressjs basic to advance, power by Node.js
Expressjs basic to advance, power by Node.jsExpressjs basic to advance, power by Node.js
Expressjs basic to advance, power by Node.js
 
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
 
JSConf: All You Can Leet
JSConf: All You Can LeetJSConf: All You Can Leet
JSConf: All You Can Leet
 
Spock: Test Well and Prosper
Spock: Test Well and ProsperSpock: Test Well and Prosper
Spock: Test Well and Prosper
 
Gl qtp day 3 2
Gl qtp day 3   2Gl qtp day 3   2
Gl qtp day 3 2
 
Teach your kids how to program with Python and the Raspberry Pi
Teach your kids how to program with Python and the Raspberry PiTeach your kids how to program with Python and the Raspberry Pi
Teach your kids how to program with Python and the Raspberry Pi
 
Mastering ElasticSearch with Ruby and Tire
Mastering ElasticSearch with Ruby and TireMastering ElasticSearch with Ruby and Tire
Mastering ElasticSearch with Ruby and Tire
 

Recently uploaded

20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
Pixlogix Infotech
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 

Recently uploaded (20)

20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 

JavaScript 1.8.5: New Features Explored

  • 1. JavaScript 1.8.5 New Features Explored by Milan Adamovsky http://milan.adamovsky.com ◆ http://www.hardcorejs.com Friday, October 4, 13
  • 2. What it is • Culmination of good-to-haves • Most features can be shimmed • Supported by all mobile devices • Supported by most modern browsers • IE8 is still in heavy use (JavaScript 1.5) Friday, October 4, 13
  • 3. Remember • Includes many features introduced since 1.5 • 1.6 • 1.7 features mainly supported in FireFox • Use reference material for all versions • Some features are deprecated Friday, October 4, 13
  • 4. What to know • Array functions • Object properties • Still doesn’t have block scope • Function features • “use strict” Friday, October 4, 13
  • 5. Quick notes • NaN, Infinity, and undefined immutable • No trailing commas in JSON.parse() • Supports “strict mode” • apply() accepts array-like object • Data properties are big Friday, October 4, 13
  • 7. “”.trim() • Introduced in 1.8.5 • Removes leading spaces • Removes trailing spaces • Works on strings Friday, October 4, 13
  • 8. Example " Hello World ! ".trim(); "Hello World !" Friday, October 4, 13
  • 10. [].map(fn, this) • Introduced in 1.6 • Does not mutate array • Works only on indexes with values • Executes fn on each item in array • Modify an array’s items without a loop Friday, October 4, 13
  • 11. Example function resolve(item) { return $(item); } var selectors = ["body", "#hello"].map(resolve); console.log(selectors); [ e.fn.init[1], e.fn.init[0] ] Friday, October 4, 13
  • 12. [].reduce(fn, first) • Introduced in 1.8 • Does not mutate array • Executes fn on each item of array • Reduce array to one value without loops • Also available .reduceRight() Friday, October 4, 13
  • 13. Example function callback(previousItem, currentItem, index, array) { console.log(previousItem, " - ", currentItem, " - ", index, " - ", array); return previousItem + " " + currentItem; } var sentence = ["three", "little", "pigs", "red", "riding", "hood"].reduce(callback); three - little - 1 - ["three", "little", "pigs", "red", "riding", "hood"] three little - pigs - 2 - ["three", "little", "pigs", "red", "riding", "hood"] three little pigs - red - 3 - ["three", "little", "pigs", "red", "riding", "hood"] three little pigs red - riding - 4 - ["three", "little", "pigs", "red", "riding", "hood"] three little pigs red riding - hood - 5 - ["three", "little", "pigs", "red", "riding", "hood"] Friday, October 4, 13
  • 14. Array.isArray(obj) • Introduced in 1.8.5 • Determine if object is truly an array • Fastest performance • Prototype is an array • Arguments are not an array Friday, October 4, 13
  • 15. Example function callback(switcher) { return switcher ? ["m", "t", "w", "t", "f"] : undefined; } Array.isArray([]); Array.isArray(new Array()); Array.isArray(callback(true)); Array.isArray(callback(false)); true true true false Friday, October 4, 13
  • 16. [].filter(fn, this) • Introduced in 1.6 • Filters an array via fn • Returns all items for which fn returns true • Doesn’t need loops • Takes optional parameter for this Friday, October 4, 13
  • 17. Example function callback(value, index, array) { return value.days === 31; } [ { days : 31, month : "January" }, { days : 28, month : "February" }, { days : 31, month : "March" }, { days : 30, month : "April" }, { days : 31, month : "May" } ].filter(callback); [ Object, Object, Object ] Friday, October 4, 13
  • 18. See also • [].forEach(fn, this) • [].toString() • [].some(fn, this) • [].every(fn, this) • [].lastIndexOf(search, index) Friday, October 4, 13
  • 20. Property descriptors • Meta data describing object • Each property has descriptor • Data descriptors • Accessor descriptors • Cannot mix both Friday, October 4, 13
  • 21. Data descriptor • Introduced in 1.8.5 • Default descriptor type • Define configuration of property values • Optional key value (defaults to undefined) • Optional key writeable (defaults to false) Friday, October 4, 13
  • 22. Example var person = {}; Object.defineProperty(person, "firstName", { configurable : true, enumerable : true, value : "Joe", writable : true }); console.log(person.firstName); person.firstName = "Jane"; console.log(person.firstName); Joe Jane Friday, October 4, 13
  • 23. Example var person = {}; Object.defineProperty(person, "firstName", { configurable : true, enumerable : true, value : "Joe", writable : false }); console.log(person.firstName); person.firstName = "Jane"; console.log(person.firstName); Joe Joe Friday, October 4, 13
  • 24. Default values • Default values apply with defineProperty() • Object literal assignment defaults to truely • Defaults to falsely with defineProperty() • All descriptors have writable attribute • All descriptors have enumerable attribute Friday, October 4, 13
  • 25. Accessor descriptor • Introduced in 1.8.5 • Bind functionality with property • Define configuration of property values • Optional key value (defaults to undefined) • Optional key writeable (defaults to false) Friday, October 4, 13
  • 26. Example var year = {}; (function () { var month = ""; Object.defineProperty(year, "month", { configurable : true, enumerable : true, get : function () { return month; }, set : function (value) { value = value.toLowerCase().substr(0, 3); month = ([ "jan", "feb", "mar" ].filter(function (val, index, arr) { return value === val; }))[0]; } }); })(); year.month = "February"; console.log(year.month); Friday, October 4, 13
  • 27. Notice • Value needs to live outside the setter • Closure is needed to protect value • Keyword let is non-standard • Use a getter to retrieve value • Logic can exist in both getter and setter Friday, October 4, 13
  • 28. Important • Properties are basis for most new features • defineProperty() defines one property • defineProperties() defines many at once Friday, October 4, 13
  • 29. Read descriptors • Use Object.getOwnPropertyDescriptor(o, prop) • Returns a property descriptor object • Object contains all descriptor attributes • Returns undefined if invalid property • Object is a normal object literal Friday, October 4, 13
  • 30. Example var person = {}; Object.defineProperty(person, "firstName", { configurable : false, enumerable : true, value : "Joe" }); console.log(Object.getOwnPropertyDescriptor(person, "firstName")); Object {value: "Joe", writable: false, enumerable: true, configurable: false} Friday, October 4, 13
  • 31. Object.keys(obj) • Returns array of properties • Only its own enumerable properties • Also works on arrays • Does not travel prototype chain Friday, October 4, 13
  • 32. Example var person = { "age" : 99, "lastName" : "Shmo" }; Object.defineProperty(person, "firstName", { configurable : true, enumerable : false, value : "Joe", writable : true }); console.log(Object.keys(person)); ["age", "lastName"] Friday, October 4, 13
  • 33. See also • for...in to list all properties • Object.getOwnPropertyNames(obj) Friday, October 4, 13
  • 34. Object.seal(obj) • Partially locks down object • Locks descriptors from being removed • Locks object from new properties • Properties can still be writable • Prototype chain remains uneffected Friday, October 4, 13
  • 35. Example var person = { "age" : 99, "lastName" : "Shmo" }; Object.defineProperty(person, "firstName", { configurable : true, enumerable : false, value : "Joe", writable : true }); console.log(Object.keys(person)); ["age", "lastName"] Friday, October 4, 13
  • 36. .preventExtensions(obj) • Prevents own properties from being added • Properties can still be removed • Does not lock down prototype Friday, October 4, 13
  • 37. Object.freeze(obj) • Complete shallow lock-down of object • Locks descriptors from being removed • Locks object from new properties • Locks properties from being modified • A frozen object gives you most security Friday, October 4, 13
  • 38. Check state • Use isSealed() to check for seal • Use isExtensible() to check extensibility • Use isFrozen() to check for freeze • States can only change to be tighter • Cannot unfreeze Friday, October 4, 13
  • 40. function(){}.bind() • Marry a context to function definition • Similar to call() and apply() • Does not execute function • Can also marry arguments to function • Called a bound function Friday, October 4, 13
  • 41. Example function sample() { console.log(this); } var boundFunction; sample(); boundFunction = sample.bind({ "first" : "Joe" } ); boundFunction(); sample(); (sample.bind({ "last" : "Shmo" } ))(); Window {top: Window, window: Window, location: Location, external: Object, chrome: Object…} Object {first: "Joe"} Window {top: Window, window: Window, location: Location, external: Object, chrome: Object…} Object {last: "Shmo"} Friday, October 4, 13
  • 42. Connect • Thank you for your time • Connect with me on LinkedIn • Join the Hardcore JavaScript community • Read my blog • Contact me via e-mail Friday, October 4, 13