30
Developer’s Life..!

Javascript Optimization Intro

Embed Size (px)

DESCRIPTION

An Introduction for Javascript Optimization techniques and deals aboutthe concepts of GC (Mark and Sweep) technique

Citation preview

Page 1: Javascript Optimization Intro

Developer’s Life..!

Page 2: Javascript Optimization Intro

Strictly Questions at last

Page 3: Javascript Optimization Intro

Who am I?

• rampicos.wordpress.com• twitter.com/rampicos• facebook.com/raamkumar.m• Code• Ramkumar Murugadoss

Page 4: Javascript Optimization Intro

What is JavaScript

• Javascript is the Programming language, first emerged to make dynamic scripts for Web pages

• What do you think about Javascript?

Page 5: Javascript Optimization Intro

Why Javascript

• What we use for: Programming Language for Web Pages

• How it was in current: Programming Language for Server-side too

• In near future: It is most wanted huge Programming Language for all

– (Harish don’t ask how?)

Page 6: Javascript Optimization Intro

Best Practices

• All know Javascript• Everyone can code in Javascript• All we want to know, how efficiently we will

write JS

Page 7: Javascript Optimization Intro

About GC

• GC is automatic• Objects are collected there is no references

longer• Javascript Uses Mark and Sweep GC method

Page 8: Javascript Optimization Intro

Avoid the global scope

• In the Global scope the Object never null, so never garbage collected

• It’s time taking and trivial process to get the reference of global scope

• If need to use global scope assign yourself null after the use

Page 9: Javascript Optimization Intro

Use Var

• Don’t forget to use var for all your variables• The Variables without var may considered to

global• You are making javascript to struggle for

finding the scope of your variable

Page 10: Javascript Optimization Intro

Get Use of Self-Calling Functions

• Have any one noticied jQuery using self calling functions

Page 11: Javascript Optimization Intro

Make your loops more efficient

Page 12: Javascript Optimization Intro

Conditional Branching

Page 13: Javascript Optimization Intro

Creating Arrays and Objects

• Use [] instead of Array– Use arrayVariable[length] = value instead of arrayVariable.push(value)

• Use {} instead of Object

Page 14: Javascript Optimization Intro

Closures

• A closure is a special kind of object that combines two things: a function, and the environment in which that function was created

• The environment consists of any local variables that were in-scope at the time that the closure was created

Page 15: Javascript Optimization Intro

Closures Cond…

Page 16: Javascript Optimization Intro

Closures Cond…

Page 17: Javascript Optimization Intro

Remove all your event listeners

• The event you added or binded must be removed when it is not in use

Page 18: Javascript Optimization Intro

Namespaces

• this prevent the global scope pollution• this protect your code from colliding with

other code or libraries

Page 19: Javascript Optimization Intro

Building String in Loops

Page 20: Javascript Optimization Intro

Coding Practice

Page 21: Javascript Optimization Intro

OOPs

• Everything in Javascript is Object based, (note there is no keyword called class in JS)

• Now the question is then how can I create the Objects and its functions?

Page 22: Javascript Optimization Intro

OOPs cond

• Creating functions in JS is considered to the Object, using prototypes you can define methods for that

Page 23: Javascript Optimization Intro

Any Guess

• What is the difference between this two codes

Page 24: Javascript Optimization Intro

Don’t D.R.Y

• Make the reusability• Make use of Namespace

Page 25: Javascript Optimization Intro

CommonJS

• The Biggest feature introduced from Node.js for reusability is CommonJS

• Make your functions as unique namespaced modules and get to use of that

• We have exports.yourfunction and module.exports as 2 ways to create CommonJS modules

• Woow now browsers support CommonJS with some libraries

Page 26: Javascript Optimization Intro

exports.your function

Page 27: Javascript Optimization Intro

module.exports

Page 28: Javascript Optimization Intro

• Javascript is Ocean we can’t cross that by swim within 60 Mins.

• Time permits we can have another session on this after sometime

Page 29: Javascript Optimization Intro

Time is Yours

Page 30: Javascript Optimization Intro

Show Ends