SlideShare uma empresa Scribd logo
1 de 15
JavaScript forC# Devs
Salvatore Di Fazio – MVP SharePoint Server
http://salvatoredifaziosharepoint.blogspot.co.uk
Twitter: @Salvodif
Why aJS session
if we speak about
SharePoint?
• Sharepoint 2013 – Javascript & jQuery big booboo to watch out
for: http://alturl.com/3xdvz
• “so everyone likes jQuery right? Even Microsoft like it, even the
SharePoint team like it. Unfortunately, 99.999% of the code you see
out there using jQuery makes a big huge mistake. And that is, to
load the $ variable in the global namespace…”
• Web 2.0 – when a client ask for a new feature, most of the
time, the comparison is one of the new social network
(Facebook,Twitter, Instagram,Yammer, etc.)
• Microsoft is pushing
Improvement
fromSharePoint
2007 to
SharePoint 2013
JavaScriptAPI for
Office
starter
• JavaScript is object based, everything is an object
• Variables created using var
• You should always use semicolons, and an object is a collection of
name/value
name: value
• JavaScript is case sensitive
• Always use strict mode, declared with use strict
• Cannot use a variable without declaring it
• Cannot define a property more than once in an object literal
• Cannot use a parameter name more than once in a function
• Cannot use reserved words
• The value of this in a function is no longer the window object
• Cannot change the members of the arguments array
• Etc...
Functions
 Start with the keyword function
 Can have a name or not
 Can have parameters or not, by default exist the arguments
param
 The delimiters of the function are { }
 A function can return a value, and that value can be itself
 Cannot be overloaded!!!
 Parameters not passed are setted undefined
 Is possible to have a function inside a function Closure
 Functions have this and it identify the current context
 Every function has a property named prototype
Null
and
undefined
• NULL
• Primitive types
• Represents the absence of value
• Evaluates to false in Boolean expressions
• UNDEFINED
• Primitive type
• Represents an unknown value
• Returned when a non-existent object property is called
• Evaluates to false in Boolean expressions
Avoid coercive
equality operators
 Objects are only equal to themselves
 Primitives are equal if the values match (“salvo” === “salvo”)
 Two sets of equality operators ( == and ===)
 never use == or != INSTEAD of === or !==
0 == '0'; //true
0 === '0'; //false
false == '0'; //true
false === '0'; //false
 Global scope
 Comparision == OR ===
 Prototype
DEMO
Classes
 We create a class in JS by a pattern:
 Using function, the most common ways
 Using object literals
 Singleton using a function
 Use it to prevent name collisions and polluting parent namespace
 Use the new keyword to invoke the constructor
 Use the prototype to expand it:
 Using it avoid to recreated every time the method when the
constructor is invoked, using the prototype avoid this effort
 ClassDEMO
Closure
Whenever you see the function keyword within another
function, the inner function has access to variables of the outer
function
http://stackoverflow.com/questions/111102/how-do-javascript-
closures-work
 ClosureDEMO
Module
 The window object in browsers is a global namespace
 Variables defined outside a function are in the global namespace
 Variables defined without the var keyword are in the global namespace
 Always create your own namespace by a pattern
 The module pattern was made by Eric Miraglia ofYUI in the 2007
 Use it to prevent name collisions and polluting parent namespace
 Keep everything tidy
 Module Export Pattern:
var MODULE = (function () {
var my = {},
privateVariable = 1;
function privateMethod() {
// ...
}
my.moduleProperty = 1;
my.moduleMethod = function () {
// ...
};
return my;
}());
 AnonymousClosures Pattern:
(function () {
// ... all vars and functions are in this scope only
// still maintains access to all globals
}());
 ModuleDEMO
Some useful links• Strict Mode - http://msdn.microsoft.com/en-us/library/ie/br230269(v=vs.94).aspx
• Strict Mode - http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/
• JavaScript info - https://developer.mozilla.org/en-US/docs/JavaScript/Reference/
• Namespace function -
https://github.com/smith/namespacedotjs/blob/master/example/sandbox.js
• TypeScript

Mais conteúdo relacionado

Mais procurados

JavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your codeJavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your code
Laurence Svekis ✔
 

Mais procurados (20)

jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)
 
Learn about Eclipse e4 from Lars Vogel at SF-JUG
Learn about Eclipse e4 from Lars Vogel at SF-JUGLearn about Eclipse e4 from Lars Vogel at SF-JUG
Learn about Eclipse e4 from Lars Vogel at SF-JUG
 
Handlebars.js
Handlebars.jsHandlebars.js
Handlebars.js
 
The Django Book, Chapter 16: django.contrib
The Django Book, Chapter 16: django.contribThe Django Book, Chapter 16: django.contrib
The Django Book, Chapter 16: django.contrib
 
Js ppt
Js pptJs ppt
Js ppt
 
FuncUnit
FuncUnitFuncUnit
FuncUnit
 
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy steps
 
Associations & JavaScript
Associations & JavaScriptAssociations & JavaScript
Associations & JavaScript
 
Jquery introduction
Jquery introductionJquery introduction
Jquery introduction
 
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - Introduction
 
User Interface Development with jQuery
User Interface Development with jQueryUser Interface Development with jQuery
User Interface Development with jQuery
 
Nothing Hard Baked: Designing the Inclusive Web
Nothing Hard Baked: Designing the Inclusive WebNothing Hard Baked: Designing the Inclusive Web
Nothing Hard Baked: Designing the Inclusive Web
 
The jQuery Library
The  jQuery LibraryThe  jQuery Library
The jQuery Library
 
Efficient use of jQuery selector
Efficient use of jQuery selectorEfficient use of jQuery selector
Efficient use of jQuery selector
 
那些年,我用 Django Admin 接的案子
那些年,我用 Django Admin 接的案子那些年,我用 Django Admin 接的案子
那些年,我用 Django Admin 接的案子
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQuery
 
Intro to jQuery
Intro to jQueryIntro to jQuery
Intro to jQuery
 
JavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your codeJavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your code
 
JQuery
JQueryJQuery
JQuery
 

Semelhante a Javascript for the c# developer

Javascript fundamentals and not
Javascript fundamentals and notJavascript fundamentals and not
Javascript fundamentals and not
Salvatore Fazio
 
Jquery Plugin
Jquery PluginJquery Plugin
Jquery Plugin
Ravi Mone
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010
Rich Helton
 

Semelhante a Javascript for the c# developer (20)

Javascript fundamentals and not
Javascript fundamentals and notJavascript fundamentals and not
Javascript fundamentals and not
 
Handlebars and Require.js
Handlebars and Require.jsHandlebars and Require.js
Handlebars and Require.js
 
Jquery Plugin
Jquery PluginJquery Plugin
Jquery Plugin
 
Handlebars & Require JS
Handlebars  & Require JSHandlebars  & Require JS
Handlebars & Require JS
 
Design patterns
Design patternsDesign patterns
Design patterns
 
JavaScript Coding with Class
JavaScript Coding with ClassJavaScript Coding with Class
JavaScript Coding with Class
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for selenium
 
JavaScript_III.pptx
JavaScript_III.pptxJavaScript_III.pptx
JavaScript_III.pptx
 
Built to last javascript for enterprise
Built to last   javascript for enterpriseBuilt to last   javascript for enterprise
Built to last javascript for enterprise
 
Dependency Injection for PHP
Dependency Injection for PHPDependency Injection for PHP
Dependency Injection for PHP
 
Jump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design PatternJump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design Pattern
 
Jump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsJump Start To Ooad And Design Patterns
Jump Start To Ooad And Design Patterns
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010
 
(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHP(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHP
 
How to crack java script certification
How to crack java script certificationHow to crack java script certification
How to crack java script certification
 
Javascript Common Design Patterns
Javascript Common Design PatternsJavascript Common Design Patterns
Javascript Common Design Patterns
 
Angular Intermediate
Angular IntermediateAngular Intermediate
Angular Intermediate
 
Django apps and ORM Beyond the basics [Meetup hosted by Prodeers.com]
Django apps and ORM Beyond the basics [Meetup hosted by Prodeers.com]Django apps and ORM Beyond the basics [Meetup hosted by Prodeers.com]
Django apps and ORM Beyond the basics [Meetup hosted by Prodeers.com]
 

Último

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Último (20)

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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
 
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...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 

Javascript for the c# developer

  • 1. JavaScript forC# Devs Salvatore Di Fazio – MVP SharePoint Server http://salvatoredifaziosharepoint.blogspot.co.uk Twitter: @Salvodif
  • 2. Why aJS session if we speak about SharePoint? • Sharepoint 2013 – Javascript & jQuery big booboo to watch out for: http://alturl.com/3xdvz • “so everyone likes jQuery right? Even Microsoft like it, even the SharePoint team like it. Unfortunately, 99.999% of the code you see out there using jQuery makes a big huge mistake. And that is, to load the $ variable in the global namespace…” • Web 2.0 – when a client ask for a new feature, most of the time, the comparison is one of the new social network (Facebook,Twitter, Instagram,Yammer, etc.) • Microsoft is pushing
  • 4. starter • JavaScript is object based, everything is an object • Variables created using var • You should always use semicolons, and an object is a collection of name/value name: value • JavaScript is case sensitive • Always use strict mode, declared with use strict • Cannot use a variable without declaring it • Cannot define a property more than once in an object literal • Cannot use a parameter name more than once in a function • Cannot use reserved words • The value of this in a function is no longer the window object • Cannot change the members of the arguments array • Etc...
  • 5. Functions  Start with the keyword function  Can have a name or not  Can have parameters or not, by default exist the arguments param  The delimiters of the function are { }  A function can return a value, and that value can be itself  Cannot be overloaded!!!  Parameters not passed are setted undefined  Is possible to have a function inside a function Closure  Functions have this and it identify the current context  Every function has a property named prototype
  • 6. Null and undefined • NULL • Primitive types • Represents the absence of value • Evaluates to false in Boolean expressions • UNDEFINED • Primitive type • Represents an unknown value • Returned when a non-existent object property is called • Evaluates to false in Boolean expressions
  • 7. Avoid coercive equality operators  Objects are only equal to themselves  Primitives are equal if the values match (“salvo” === “salvo”)  Two sets of equality operators ( == and ===)  never use == or != INSTEAD of === or !== 0 == '0'; //true 0 === '0'; //false false == '0'; //true false === '0'; //false
  • 8.  Global scope  Comparision == OR ===  Prototype DEMO
  • 9. Classes  We create a class in JS by a pattern:  Using function, the most common ways  Using object literals  Singleton using a function  Use it to prevent name collisions and polluting parent namespace  Use the new keyword to invoke the constructor  Use the prototype to expand it:  Using it avoid to recreated every time the method when the constructor is invoked, using the prototype avoid this effort
  • 11. Closure Whenever you see the function keyword within another function, the inner function has access to variables of the outer function http://stackoverflow.com/questions/111102/how-do-javascript- closures-work
  • 13. Module  The window object in browsers is a global namespace  Variables defined outside a function are in the global namespace  Variables defined without the var keyword are in the global namespace  Always create your own namespace by a pattern  The module pattern was made by Eric Miraglia ofYUI in the 2007  Use it to prevent name collisions and polluting parent namespace  Keep everything tidy  Module Export Pattern: var MODULE = (function () { var my = {}, privateVariable = 1; function privateMethod() { // ... } my.moduleProperty = 1; my.moduleMethod = function () { // ... }; return my; }());  AnonymousClosures Pattern: (function () { // ... all vars and functions are in this scope only // still maintains access to all globals }());
  • 15. Some useful links• Strict Mode - http://msdn.microsoft.com/en-us/library/ie/br230269(v=vs.94).aspx • Strict Mode - http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/ • JavaScript info - https://developer.mozilla.org/en-US/docs/JavaScript/Reference/ • Namespace function - https://github.com/smith/namespacedotjs/blob/master/example/sandbox.js • TypeScript

Notas do Editor

  1. Strict mode: http://www.nczonline.net/blog/2012/03/13/its-time-to-start-using-javascript-strict-mode/