java script ppt

Post on 10-May-2015

3.623 Views

Category:

Health & Medicine

4 Downloads

Preview:

Click to see full reader

DESCRIPTION

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

TRANSCRIPT

JAVASCRIPT DOJO

Lessons and thoughts from DevWeek

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

Nobody knows

JavaScript!

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”

Prefer strict equals === to ==

QUNIT

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}

HOISTING

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

Function scope means that all variables and parameters

declared inside a function are visible everywhere within the

function.

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

};

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

TECHNIQUES

• Constructor protection

• Encapsulation

• Placing methods on the prototype

• Self executing functions

• Namespaces

• Module Pattern / Revealing module pattern

CONSTRUCTOR PROTECTION

STORE FUNCTIONS ON THE PROTOTYPE

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

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.

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

top related