SlideShare une entreprise Scribd logo
1  sur  16
Introduction to Underscore.js 
By Jitendra Zaa 
http://JitendraZaa.com
Why do I need one more Library ? 
• For DOM, JQuery is Awesome. But what if you are dealing with non 
DOM operations and requirements like MVC or templating ? 
• Lots of functions available for Collections. (Which is not supported by 
Native Javascript or JQuery) 
• Client Side Templating. 
• Supports MVC programming model. 
• Only in 4KB , Your life will become a lot easier.
Getting Started 
• Underscore requires JQuery library as a prerequisite. 
• You can get Underscore.js from here : 
http://documentcloud.github.com/underscore/docs/underscore.htm 
l 
• Underscore creates and exposes all its functionality via a single 
object, in global scope. This object is the titular underscore 
character, _.
Example 
Lets assume, we have array of key value pair (Map) in JavaScript like 
var compKeyVal = [ 
{company : 'Salesforce', Founder : 'Marc Benioff'}, 
{company : 'Apple', Founder : 'steve jobs'}, 
{company : 'Oracle', Founder : 'Larry Ellison'} 
]; 
Requirement : Get Array which will contain name of Founders Only from 
above Key Value Pair. It is so simple as writing only one Line 
var Founders = _.pluck (compKeyVal, 'Founder');
Functional or Object Oriented ? 
Few Programmers are not comfortable with Functional way and may 
argue that Object Oriented way of coding is more straight forward. 
Same example of last slide can be re-written in more Object Oriented 
way as : 
var Founders = _(compKeyVal).pluck ('Founder'); 
Which one is better ? 
There is no real “right” way, Its all up to you.
Collections Method
Collection 
• Array of String, Object or Key-value considered as a collection. 
Example : 
• [0,4,5,6,7] 
• [“StringB”,” StringA”,” StringD”,” StringE”,” StringG”] 
• [obj1,obj2,obj3] 
• [{Key : Val, Key1 : Val1}, {Key : Val, Key1 : Val1}]
Sample Array 
• Throughout the slides we will use below collection to test different 
methods of Underscore.js. This is array of Key value Pairs. 
var compKeyVal = [ 
{company : 'Salesforce', Founder : 'Marc Benioff‘, year : 
1999}, 
{company : 'Apple', Founder : 'steve jobs', year : 1976}, 
{company : 'Oracle', Founder : 'Larry Ellison', year : 1977} 
];
Select 
• This function is used to Select subset of collection. 
• Example : Get all values which are founded after 1980. 
var ans = _(compKeyVal).select(function(compKey){ return 
compKey.year > 1980; }); 
console.log(ans[0]); 
Output : 
Object {company: "Salesforce", Founder: "Marc Benioff", year: 1999}
Pluck 
This method extracts simple one dimensional array from collection with 
specified property. 
Requirement : Get Array which will contain name of “Founders” Only from 
above collection. It is so simple as writing only one Line 
var Founders = _.pluck (compKeyVal, 'Founder'); 
console.log(Founders); 
Output : 
["Marc Benioff", "steve jobs", " Larry Ellison"]
Map 
• Creates array from collection Where each element of resultant array 
changed through function. 
Example : 
var incNames = _(compKeyVal).pluck('company').map(function 
(value){return value + '.Inc'}); 
console.log(incNames); 
Output: 
["Salesforce.Inc", "Apple.Inc", "Oracle.Inc"]
All 
• Returns Either True or False, If every element in Array passed some 
Criteria or Not ? 
• Example : Return True if every element in array is greater than 1970. 
var yearArray = _(compKeyVal).pluck('year'); 
var retVal = _(yearArray).all(function (value){return 
value>1970; }); 
console.log(retVal); 
Output : True
Arrays Method
Uniq 
This Method removes Duplicate values from array. 
var unVal = 
_.uniq(['Shiva','Soft','Salesforce','Shiva','Soft','Salesforce' 
,'Shiva','Soft','Salesforce','Shiva','Soft','Salesforce']); 
console.log(unVal); 
Output : ["Shiva", "Soft", "Salesforce"]
Range 
Used to create array with values between specified range. 
Syntax : 
_.range(Starting Number, Ending Number, Number to Increment); 
Example : 
var randVals = _.range(0, 100, 11); 
console.log(randVals); 
Output : 
[0, 11, 22, 33, 44, 55, 66, 77, 88, 99]
Intersection 
This method returns Common Elements between Arrays. 
var arr1 = [1,2,3,4,5,6,7]; 
var arr2 = [1,3,6,9,10,11,45,67]; 
var arr3 = [1,6,697,180,131,405,617]; 
var common = _.intersection(arr1, arr2, arr3 ); 
console.log(common); 
Output: 
[1, 6]

Contenu connexe

Tendances

Recipes to build Code Generators for Non-Xtext Models with Xtend
Recipes to build Code Generators for Non-Xtext Models with XtendRecipes to build Code Generators for Non-Xtext Models with Xtend
Recipes to build Code Generators for Non-Xtext Models with XtendKarsten Thoms
 
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...andreaslubbe
 
React Native One Day
React Native One DayReact Native One Day
React Native One DayTroy Miles
 
React Native Evening
React Native EveningReact Native Evening
React Native EveningTroy Miles
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScriptYakov Fain
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN StackTroy Miles
 
Dependency Injection @ AngularJS
Dependency Injection @ AngularJSDependency Injection @ AngularJS
Dependency Injection @ AngularJSRan Mizrahi
 
Artem Yavorsky "99 ways to take away your ugly polyfills"
Artem Yavorsky "99 ways to take away your ugly polyfills"Artem Yavorsky "99 ways to take away your ugly polyfills"
Artem Yavorsky "99 ways to take away your ugly polyfills"Fwdays
 
Protocol in Swift
Protocol in SwiftProtocol in Swift
Protocol in SwiftYusuke Kita
 
How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...Codemotion
 
Unit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeUnit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeJosh Mock
 
Angular JS Unit Testing - Overview
Angular JS Unit Testing - OverviewAngular JS Unit Testing - Overview
Angular JS Unit Testing - OverviewThirumal Sakthivel
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptVisual Engineering
 
An approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSocketsAn approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSocketsAndrei Sebastian Cîmpean
 
Porting legacy apps to Griffon
Porting legacy apps to GriffonPorting legacy apps to Griffon
Porting legacy apps to GriffonJames Williams
 
How to learn Laravel5 application from Authentication
How to learn Laravel5 application from AuthenticationHow to learn Laravel5 application from Authentication
How to learn Laravel5 application from AuthenticationMasashi Shinbara
 
Protocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftProtocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftOleksandr Stepanov
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingVisual Engineering
 
Douglas Crockford: Serversideness
Douglas Crockford: ServersidenessDouglas Crockford: Serversideness
Douglas Crockford: ServersidenessWebExpo
 

Tendances (20)

Recipes to build Code Generators for Non-Xtext Models with Xtend
Recipes to build Code Generators for Non-Xtext Models with XtendRecipes to build Code Generators for Non-Xtext Models with Xtend
Recipes to build Code Generators for Non-Xtext Models with Xtend
 
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
 
React Native One Day
React Native One DayReact Native One Day
React Native One Day
 
React Native Evening
React Native EveningReact Native Evening
React Native Evening
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN Stack
 
Dependency Injection @ AngularJS
Dependency Injection @ AngularJSDependency Injection @ AngularJS
Dependency Injection @ AngularJS
 
Artem Yavorsky "99 ways to take away your ugly polyfills"
Artem Yavorsky "99 ways to take away your ugly polyfills"Artem Yavorsky "99 ways to take away your ugly polyfills"
Artem Yavorsky "99 ways to take away your ugly polyfills"
 
Protocol in Swift
Protocol in SwiftProtocol in Swift
Protocol in Swift
 
How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...
 
Unit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeUnit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and Node
 
Angular JS Unit Testing - Overview
Angular JS Unit Testing - OverviewAngular JS Unit Testing - Overview
Angular JS Unit Testing - Overview
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
 
An approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSocketsAn approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSockets
 
Porting legacy apps to Griffon
Porting legacy apps to GriffonPorting legacy apps to Griffon
Porting legacy apps to Griffon
 
How to learn Laravel5 application from Authentication
How to learn Laravel5 application from AuthenticationHow to learn Laravel5 application from Authentication
How to learn Laravel5 application from Authentication
 
Protocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftProtocol-Oriented Programming in Swift
Protocol-Oriented Programming in Swift
 
Promise pattern
Promise patternPromise pattern
Promise pattern
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
 
Douglas Crockford: Serversideness
Douglas Crockford: ServersidenessDouglas Crockford: Serversideness
Douglas Crockford: Serversideness
 

Similaire à Introduction to underscore.js

JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformationLars Marius Garshol
 
Raffaele Rialdi
Raffaele RialdiRaffaele Rialdi
Raffaele RialdiCodeFest
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleRaimonds Simanovskis
 
Кирилл Безпалый, .NET Developer, Ciklum
Кирилл Безпалый, .NET Developer, CiklumКирилл Безпалый, .NET Developer, Ciklum
Кирилл Безпалый, .NET Developer, CiklumAlina Vilk
 
Introduction tomongodb
Introduction tomongodbIntroduction tomongodb
Introduction tomongodbLee Theobald
 
Spring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard WolffSpring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard WolffJAX London
 
The openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query LanguageThe openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query LanguageNeo4j
 
Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!Eric Phan
 
How and Where in GLORP
How and Where in GLORPHow and Where in GLORP
How and Where in GLORPESUG
 
Angular from a Different Angle
Angular from a Different AngleAngular from a Different Angle
Angular from a Different AngleJeremy Likness
 
Javascript and Jquery Best practices
Javascript and Jquery Best practicesJavascript and Jquery Best practices
Javascript and Jquery Best practicesSultan Khan
 
Javascript Everywhere
Javascript EverywhereJavascript Everywhere
Javascript EverywherePascal Rettig
 
Exciting JavaScript - Part II
Exciting JavaScript - Part IIExciting JavaScript - Part II
Exciting JavaScript - Part IIEugene Lazutkin
 
2CPP06 - Arrays and Pointers
2CPP06 - Arrays and Pointers2CPP06 - Arrays and Pointers
2CPP06 - Arrays and PointersMichael Heron
 
First class Variables in Pharo
First class Variables in PharoFirst class Variables in Pharo
First class Variables in PharoESUG
 
Boost delivery stream with code discipline engineering
Boost delivery stream with code discipline engineeringBoost delivery stream with code discipline engineering
Boost delivery stream with code discipline engineeringMiro Wengner
 
Object Oriented Programming In JavaScript
Object Oriented Programming In JavaScriptObject Oriented Programming In JavaScript
Object Oriented Programming In JavaScriptForziatech
 
JavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingJavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingRadoslav Georgiev
 

Similaire à Introduction to underscore.js (20)

JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformation
 
Raffaele Rialdi
Raffaele RialdiRaffaele Rialdi
Raffaele Rialdi
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on Oracle
 
Кирилл Безпалый, .NET Developer, Ciklum
Кирилл Безпалый, .NET Developer, CiklumКирилл Безпалый, .NET Developer, Ciklum
Кирилл Безпалый, .NET Developer, Ciklum
 
Introduction tomongodb
Introduction tomongodbIntroduction tomongodb
Introduction tomongodb
 
Spring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard WolffSpring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard Wolff
 
The openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query LanguageThe openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query Language
 
Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!
 
How and Where in GLORP
How and Where in GLORPHow and Where in GLORP
How and Where in GLORP
 
Angular from a Different Angle
Angular from a Different AngleAngular from a Different Angle
Angular from a Different Angle
 
Javascript and Jquery Best practices
Javascript and Jquery Best practicesJavascript and Jquery Best practices
Javascript and Jquery Best practices
 
Javascript Everywhere
Javascript EverywhereJavascript Everywhere
Javascript Everywhere
 
Exciting JavaScript - Part II
Exciting JavaScript - Part IIExciting JavaScript - Part II
Exciting JavaScript - Part II
 
Scala and Spring
Scala and SpringScala and Spring
Scala and Spring
 
2CPP06 - Arrays and Pointers
2CPP06 - Arrays and Pointers2CPP06 - Arrays and Pointers
2CPP06 - Arrays and Pointers
 
Variables in Pharo5
Variables in Pharo5Variables in Pharo5
Variables in Pharo5
 
First class Variables in Pharo
First class Variables in PharoFirst class Variables in Pharo
First class Variables in Pharo
 
Boost delivery stream with code discipline engineering
Boost delivery stream with code discipline engineeringBoost delivery stream with code discipline engineering
Boost delivery stream with code discipline engineering
 
Object Oriented Programming In JavaScript
Object Oriented Programming In JavaScriptObject Oriented Programming In JavaScript
Object Oriented Programming In JavaScript
 
JavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingJavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft Training
 

Plus de Jitendra Zaa

Episode 13 - Advanced Apex Triggers
Episode 13 - Advanced Apex TriggersEpisode 13 - Advanced Apex Triggers
Episode 13 - Advanced Apex TriggersJitendra Zaa
 
Episode 18 - Asynchronous Apex
Episode 18 - Asynchronous ApexEpisode 18 - Asynchronous Apex
Episode 18 - Asynchronous ApexJitendra Zaa
 
Episode 15 - Basics of Javascript
Episode 15 - Basics of JavascriptEpisode 15 - Basics of Javascript
Episode 15 - Basics of JavascriptJitendra Zaa
 
Episode 23 - Design Pattern 3
Episode 23 - Design Pattern 3Episode 23 - Design Pattern 3
Episode 23 - Design Pattern 3Jitendra Zaa
 
Episode 24 - Live Q&A for getting started with Salesforce
Episode 24 - Live Q&A for getting started with SalesforceEpisode 24 - Live Q&A for getting started with Salesforce
Episode 24 - Live Q&A for getting started with SalesforceJitendra Zaa
 
Episode 22 - Design Pattern 2
Episode 22 - Design Pattern 2Episode 22 - Design Pattern 2
Episode 22 - Design Pattern 2Jitendra Zaa
 
Episode 21 - Design Pattern 1
Episode 21 - Design Pattern 1Episode 21 - Design Pattern 1
Episode 21 - Design Pattern 1Jitendra Zaa
 
Episode 20 - Trigger Frameworks in Salesforce
Episode 20 - Trigger Frameworks in SalesforceEpisode 20 - Trigger Frameworks in Salesforce
Episode 20 - Trigger Frameworks in SalesforceJitendra Zaa
 
Episode 19 - Asynchronous Apex - Batch apex & schedulers
Episode 19 - Asynchronous Apex - Batch apex & schedulersEpisode 19 - Asynchronous Apex - Batch apex & schedulers
Episode 19 - Asynchronous Apex - Batch apex & schedulersJitendra Zaa
 
Episode 17 - Handling Events in Lightning Web Component
Episode 17 - Handling Events in Lightning Web ComponentEpisode 17 - Handling Events in Lightning Web Component
Episode 17 - Handling Events in Lightning Web ComponentJitendra Zaa
 
Episode 16 - Introduction to LWC
Episode 16 - Introduction to LWCEpisode 16 - Introduction to LWC
Episode 16 - Introduction to LWCJitendra Zaa
 
Introduction to mulesoft - Alpharetta Developer Group Meet
Introduction to mulesoft - Alpharetta Developer Group MeetIntroduction to mulesoft - Alpharetta Developer Group Meet
Introduction to mulesoft - Alpharetta Developer Group MeetJitendra Zaa
 
Episode 12 - Basics of Trigger
Episode 12 - Basics of TriggerEpisode 12 - Basics of Trigger
Episode 12 - Basics of TriggerJitendra Zaa
 
Episode 11 building & exposing rest api in salesforce v1.0
Episode 11   building & exposing rest api in salesforce v1.0Episode 11   building & exposing rest api in salesforce v1.0
Episode 11 building & exposing rest api in salesforce v1.0Jitendra Zaa
 
Episode 10 - External Services in Salesforce
Episode 10 - External Services in SalesforceEpisode 10 - External Services in Salesforce
Episode 10 - External Services in SalesforceJitendra Zaa
 
Episode 14 - Basics of HTML for Salesforce
Episode 14 - Basics of HTML for SalesforceEpisode 14 - Basics of HTML for Salesforce
Episode 14 - Basics of HTML for SalesforceJitendra Zaa
 
South East Dreamin 2019
South East Dreamin 2019South East Dreamin 2019
South East Dreamin 2019Jitendra Zaa
 
Episode 9 - Building soap integrations in salesforce
Episode 9 - Building soap integrations  in salesforceEpisode 9 - Building soap integrations  in salesforce
Episode 9 - Building soap integrations in salesforceJitendra Zaa
 
Episode 8 - Path To Code - Integrate Salesforce with external system using R...
Episode 8  - Path To Code - Integrate Salesforce with external system using R...Episode 8  - Path To Code - Integrate Salesforce with external system using R...
Episode 8 - Path To Code - Integrate Salesforce with external system using R...Jitendra Zaa
 
Episode 6 - DML, Transaction and Error handling in Salesforce
Episode 6 - DML, Transaction and Error handling in SalesforceEpisode 6 - DML, Transaction and Error handling in Salesforce
Episode 6 - DML, Transaction and Error handling in SalesforceJitendra Zaa
 

Plus de Jitendra Zaa (20)

Episode 13 - Advanced Apex Triggers
Episode 13 - Advanced Apex TriggersEpisode 13 - Advanced Apex Triggers
Episode 13 - Advanced Apex Triggers
 
Episode 18 - Asynchronous Apex
Episode 18 - Asynchronous ApexEpisode 18 - Asynchronous Apex
Episode 18 - Asynchronous Apex
 
Episode 15 - Basics of Javascript
Episode 15 - Basics of JavascriptEpisode 15 - Basics of Javascript
Episode 15 - Basics of Javascript
 
Episode 23 - Design Pattern 3
Episode 23 - Design Pattern 3Episode 23 - Design Pattern 3
Episode 23 - Design Pattern 3
 
Episode 24 - Live Q&A for getting started with Salesforce
Episode 24 - Live Q&A for getting started with SalesforceEpisode 24 - Live Q&A for getting started with Salesforce
Episode 24 - Live Q&A for getting started with Salesforce
 
Episode 22 - Design Pattern 2
Episode 22 - Design Pattern 2Episode 22 - Design Pattern 2
Episode 22 - Design Pattern 2
 
Episode 21 - Design Pattern 1
Episode 21 - Design Pattern 1Episode 21 - Design Pattern 1
Episode 21 - Design Pattern 1
 
Episode 20 - Trigger Frameworks in Salesforce
Episode 20 - Trigger Frameworks in SalesforceEpisode 20 - Trigger Frameworks in Salesforce
Episode 20 - Trigger Frameworks in Salesforce
 
Episode 19 - Asynchronous Apex - Batch apex & schedulers
Episode 19 - Asynchronous Apex - Batch apex & schedulersEpisode 19 - Asynchronous Apex - Batch apex & schedulers
Episode 19 - Asynchronous Apex - Batch apex & schedulers
 
Episode 17 - Handling Events in Lightning Web Component
Episode 17 - Handling Events in Lightning Web ComponentEpisode 17 - Handling Events in Lightning Web Component
Episode 17 - Handling Events in Lightning Web Component
 
Episode 16 - Introduction to LWC
Episode 16 - Introduction to LWCEpisode 16 - Introduction to LWC
Episode 16 - Introduction to LWC
 
Introduction to mulesoft - Alpharetta Developer Group Meet
Introduction to mulesoft - Alpharetta Developer Group MeetIntroduction to mulesoft - Alpharetta Developer Group Meet
Introduction to mulesoft - Alpharetta Developer Group Meet
 
Episode 12 - Basics of Trigger
Episode 12 - Basics of TriggerEpisode 12 - Basics of Trigger
Episode 12 - Basics of Trigger
 
Episode 11 building & exposing rest api in salesforce v1.0
Episode 11   building & exposing rest api in salesforce v1.0Episode 11   building & exposing rest api in salesforce v1.0
Episode 11 building & exposing rest api in salesforce v1.0
 
Episode 10 - External Services in Salesforce
Episode 10 - External Services in SalesforceEpisode 10 - External Services in Salesforce
Episode 10 - External Services in Salesforce
 
Episode 14 - Basics of HTML for Salesforce
Episode 14 - Basics of HTML for SalesforceEpisode 14 - Basics of HTML for Salesforce
Episode 14 - Basics of HTML for Salesforce
 
South East Dreamin 2019
South East Dreamin 2019South East Dreamin 2019
South East Dreamin 2019
 
Episode 9 - Building soap integrations in salesforce
Episode 9 - Building soap integrations  in salesforceEpisode 9 - Building soap integrations  in salesforce
Episode 9 - Building soap integrations in salesforce
 
Episode 8 - Path To Code - Integrate Salesforce with external system using R...
Episode 8  - Path To Code - Integrate Salesforce with external system using R...Episode 8  - Path To Code - Integrate Salesforce with external system using R...
Episode 8 - Path To Code - Integrate Salesforce with external system using R...
 
Episode 6 - DML, Transaction and Error handling in Salesforce
Episode 6 - DML, Transaction and Error handling in SalesforceEpisode 6 - DML, Transaction and Error handling in Salesforce
Episode 6 - DML, Transaction and Error handling in Salesforce
 

Dernier

Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Servicegwenoracqe6
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceDelhi Call girls
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024APNIC
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGAPNIC
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Roomdivyansh0kumar0
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Sheetaleventcompany
 
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya Shirtrahman018755
 
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130  Available With RoomVIP Kolkata Call Girl Alambazar 👉 8250192130  Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Roomdivyansh0kumar0
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...APNIC
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Roomgirls4nights
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Servicesexy call girls service in goa
 
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts servicevipmodelshub1
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebJames Anderson
 

Dernier (20)

Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
 
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOG
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
 
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
 
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130  Available With RoomVIP Kolkata Call Girl Alambazar 👉 8250192130  Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
 
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
 
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 

Introduction to underscore.js

  • 1. Introduction to Underscore.js By Jitendra Zaa http://JitendraZaa.com
  • 2. Why do I need one more Library ? • For DOM, JQuery is Awesome. But what if you are dealing with non DOM operations and requirements like MVC or templating ? • Lots of functions available for Collections. (Which is not supported by Native Javascript or JQuery) • Client Side Templating. • Supports MVC programming model. • Only in 4KB , Your life will become a lot easier.
  • 3. Getting Started • Underscore requires JQuery library as a prerequisite. • You can get Underscore.js from here : http://documentcloud.github.com/underscore/docs/underscore.htm l • Underscore creates and exposes all its functionality via a single object, in global scope. This object is the titular underscore character, _.
  • 4. Example Lets assume, we have array of key value pair (Map) in JavaScript like var compKeyVal = [ {company : 'Salesforce', Founder : 'Marc Benioff'}, {company : 'Apple', Founder : 'steve jobs'}, {company : 'Oracle', Founder : 'Larry Ellison'} ]; Requirement : Get Array which will contain name of Founders Only from above Key Value Pair. It is so simple as writing only one Line var Founders = _.pluck (compKeyVal, 'Founder');
  • 5. Functional or Object Oriented ? Few Programmers are not comfortable with Functional way and may argue that Object Oriented way of coding is more straight forward. Same example of last slide can be re-written in more Object Oriented way as : var Founders = _(compKeyVal).pluck ('Founder'); Which one is better ? There is no real “right” way, Its all up to you.
  • 7. Collection • Array of String, Object or Key-value considered as a collection. Example : • [0,4,5,6,7] • [“StringB”,” StringA”,” StringD”,” StringE”,” StringG”] • [obj1,obj2,obj3] • [{Key : Val, Key1 : Val1}, {Key : Val, Key1 : Val1}]
  • 8. Sample Array • Throughout the slides we will use below collection to test different methods of Underscore.js. This is array of Key value Pairs. var compKeyVal = [ {company : 'Salesforce', Founder : 'Marc Benioff‘, year : 1999}, {company : 'Apple', Founder : 'steve jobs', year : 1976}, {company : 'Oracle', Founder : 'Larry Ellison', year : 1977} ];
  • 9. Select • This function is used to Select subset of collection. • Example : Get all values which are founded after 1980. var ans = _(compKeyVal).select(function(compKey){ return compKey.year > 1980; }); console.log(ans[0]); Output : Object {company: "Salesforce", Founder: "Marc Benioff", year: 1999}
  • 10. Pluck This method extracts simple one dimensional array from collection with specified property. Requirement : Get Array which will contain name of “Founders” Only from above collection. It is so simple as writing only one Line var Founders = _.pluck (compKeyVal, 'Founder'); console.log(Founders); Output : ["Marc Benioff", "steve jobs", " Larry Ellison"]
  • 11. Map • Creates array from collection Where each element of resultant array changed through function. Example : var incNames = _(compKeyVal).pluck('company').map(function (value){return value + '.Inc'}); console.log(incNames); Output: ["Salesforce.Inc", "Apple.Inc", "Oracle.Inc"]
  • 12. All • Returns Either True or False, If every element in Array passed some Criteria or Not ? • Example : Return True if every element in array is greater than 1970. var yearArray = _(compKeyVal).pluck('year'); var retVal = _(yearArray).all(function (value){return value>1970; }); console.log(retVal); Output : True
  • 14. Uniq This Method removes Duplicate values from array. var unVal = _.uniq(['Shiva','Soft','Salesforce','Shiva','Soft','Salesforce' ,'Shiva','Soft','Salesforce','Shiva','Soft','Salesforce']); console.log(unVal); Output : ["Shiva", "Soft", "Salesforce"]
  • 15. Range Used to create array with values between specified range. Syntax : _.range(Starting Number, Ending Number, Number to Increment); Example : var randVals = _.range(0, 100, 11); console.log(randVals); Output : [0, 11, 22, 33, 44, 55, 66, 77, 88, 99]
  • 16. Intersection This method returns Common Elements between Arrays. var arr1 = [1,2,3,4,5,6,7]; var arr2 = [1,3,6,9,10,11,45,67]; var arr3 = [1,6,697,180,131,405,617]; var common = _.intersection(arr1, arr2, arr3 ); console.log(common); Output: [1, 6]