Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Java script ppt

23,305 views

Published on

DOJO session from the IT team at The Health and Social Care Information Centre - All you need to know about Java Script!

Published in: Health & Medicine, Technology

Java script ppt

  1. 1. JAVASCRIPT DOJO Lessons and thoughts from DevWeek
  2. 2. TALKS ATTENDED • “Modern JavaScript” - K. Scott Allen • “Just because it’s JavaScript doesn’t give you the right to write rubbish!” – Hadi Hariri • Mobile development with MVC4 and jQuery Mobile – Brock Allen
  3. 3. Nobody knows JavaScript!
  4. 4. DOUBLE AND TRIPLE EQUALS a)1 == “1” a)1 == true a)“1” == true a)1 == “ 1 “ a)1 == [1] f) null == undefined f) 1 == 1 f) “ “ == false f) NaN == NaN f) 1 == “true”
  5. 5. Prefer strict equals === to ==
  6. 6. QUNIT
  7. 7. SCOPE A/ (function () { if (true) { var functionScope = "functionScope"; } return functionScope; })(); B/ var functionScope = "functionScope"; (function () { return functionScope; })(); C/ (function () { var test = function () { var functionScope = "functionScope"; } return functionScope; })(); D/ (function () { var functionScope = 0; var functionScope = “functionScope”; return function }
  8. 8. HOISTING http://elegantcode.com/2010/12/24/basic-javascript-part-5-hoisting/
  9. 9. Function scope means that all variables and parameters declared inside a function are visible everywhere within the function.
  10. 10. FUNCTION DECLARATIONS VS FUNCTION EXPRESSIONS Function Declaration function functionDeclaration() { return “I’m a function declaration”; } Function Expression var functionExpression = function() { return “I’m a function expression”; };
  11. 11. AUTOMATIC SEMICOLON INSERTION Using semicolons in JavaScript is optional BUT JavaScript inserts them automatically. Don't forget to use new on constructor functions. New and This
  12. 12. TECHNIQUES • Constructor protection • Encapsulation • Placing methods on the prototype • Self executing functions • Namespaces • Module Pattern / Revealing module pattern
  13. 13. CONSTRUCTOR PROTECTION
  14. 14. STORE FUNCTIONS ON THE PROTOTYPE
  15. 15. HADI HARIRI • “It’s just JavaScript!” • “JavaScript is write once code – you never want to go back to it and change it” • “People think that JavaScript is not maintainable.” • “People think SRP doesn’t exist in JavaScript – how can a class have a single responsibility if there isn’t a class” • “We care in C#, we care in Java....why not JavaScript?”
  16. 16. NEXT STEPS • Know JavaScript better. • Be able to write and run tests easily in Visual Studio. • Write real world JavaScript tests with mocking. • Get intellisense in Visual Studio • Be able to run tests as part of Team City build • Have tools which will help me improve the
  17. 17. USEFUL LINKS • K Scott Allen’s blog - www.odetocode.com/blogs/all • Hadi Hariri , same talk in Norway – http://vimeo.com/43536490 • Basic JavaScript blog posts – http://elegantcode.com/2011/03/24/basic- javascript-part-12-function-hoisting • JavaScript sketch pad – http://jsfiddle.net • Free Book (now published by O’Reilly) based on ECMAScript version 3 http://javascriptenlightment.com/JavaScript_Enlightenment.pdf • JavaScript performance test bed – http://jsperf.com

×