Java script ppt

17
JAVASCRIPT DOJO Lessons and thoughts from DevWeek

description

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

Transcript of Java script ppt

Page 1: Java script ppt

JAVASCRIPT DOJO

Lessons and thoughts from DevWeek

Page 2: Java script ppt

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

Page 3: Java script ppt

Nobody knows

JavaScript!

Page 4: Java script ppt

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”

Page 5: Java script ppt

Prefer strict equals === to ==

Page 6: Java script ppt

QUNIT

Page 7: Java script ppt

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}

Page 8: Java script ppt

HOISTING

http://elegantcode.com/2010/12/24/basic-javascript-part-5-hoisting/

Page 9: Java script ppt

Function scope means that all variables and parameters

declared inside a function are visible everywhere within the

function.

Page 10: Java script ppt

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”;

};

Page 11: Java script ppt

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

Page 12: Java script ppt

TECHNIQUES

• Constructor protection

• Encapsulation

• Placing methods on the prototype

• Self executing functions

• Namespaces

• Module Pattern / Revealing module pattern

Page 13: Java script ppt

CONSTRUCTOR PROTECTION

Page 14: Java script ppt

STORE FUNCTIONS ON THE PROTOTYPE

Page 15: Java script ppt

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?”

Page 16: Java script ppt

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 quality of my code.

Page 17: Java script ppt

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