javascript best practices and intro to titanium

30
Javascript DEVELOPER’S LIFE

Upload: techday7

Post on 11-May-2015

865 views

Category:

Education


0 download

DESCRIPTION

Javascript Best Practices Presented by Ramkumar Murugadoss at Techday7 Chennai Meetup on Nov 24 2012

TRANSCRIPT

Page 1: Javascript Best Practices and Intro to Titanium

JavascriptDEVELOPER’S LIFE

Page 2: Javascript Best Practices and Intro to Titanium

Who am I?

• Ramkumar Murugadoss

• @rampicos

• facebook.com/raamkumar.m

• Code

Page 3: Javascript Best Practices and Intro to Titanium

What is JavaScript

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

• What do you think about Javascript?

Page 4: Javascript Best Practices and Intro to Titanium

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

Page 5: Javascript Best Practices and Intro to Titanium

Best Practices

• All we know Javascript

• Everyone can code in Javascript

• All we want to know, how efficiently we will write JS

Page 6: Javascript Best Practices and Intro to Titanium

About GC

• GC is automatic

• Objects are collected there is no references longer

• Javascript Uses Mark and Sweep GC method

Page 7: Javascript Best Practices and Intro to Titanium

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 8: Javascript Best Practices and Intro to Titanium

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 9: Javascript Best Practices and Intro to Titanium

Get Use of Self-Calling Functions

• Have any one noticied jQuery using self calling functions

Page 10: Javascript Best Practices and Intro to Titanium

What will be the result?

Page 11: Javascript Best Practices and Intro to Titanium

Make your loops more efficient

Page 12: Javascript Best Practices and Intro to Titanium

Conditional Branching

Page 13: Javascript Best Practices and Intro to Titanium

Creating Arrays and Objects

• Use [] instead of Array• Use arrayVariable[length] = value instead of

arrayVariable.push(value)

• Use {} instead of Object

Page 14: Javascript Best Practices and Intro to Titanium

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 Best Practices and Intro to Titanium

Closures Cond…

 

Page 16: Javascript Best Practices and Intro to Titanium

Closures Cond…

Page 17: Javascript Best Practices and Intro to Titanium

Namespaces

• this prevent the global scope pollution

• this protect your code from colliding with other code or libraries

Page 18: Javascript Best Practices and Intro to Titanium

Building String in Loops

Page 19: Javascript Best Practices and Intro to Titanium

Small Intro to 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 20: Javascript Best Practices and Intro to Titanium

OOPs cond

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

Page 21: Javascript Best Practices and Intro to Titanium

Any Guess

• What is the difference between this two codes

Page 22: Javascript Best Practices and Intro to Titanium

Don’t D.R.Y

• Make the reusability

• Make use of Namespace

Page 23: Javascript Best Practices and Intro to Titanium
Page 24: Javascript Best Practices and Intro to Titanium

Cross Platform Mobile Applications

• What are Cross Platform Mobile Applications ?

• Why build Cross Platform ?

• What are the most popular development framework available ?

• Which framework should I use?

Page 25: Javascript Best Practices and Intro to Titanium

Why Titanium

• Code Once Build Everywhere

• Native look and feel

• Has more than 5,500+ device level APIs for iOS and Android

• Object based Javascript only

• In build Analytics

• In build Cloud integration support (ACS)

• Much more

Page 26: Javascript Best Practices and Intro to Titanium

What to do to start with Titanium today?

Signup and download http://my.appcelerator.com

Follow the “Quick Start” https://wiki.appcelerator.org/display/guides/home

You’re ready to be a Titanium developer!

Page 27: Javascript Best Practices and Intro to Titanium

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 28: Javascript Best Practices and Intro to Titanium

exports.your function

Page 29: Javascript Best Practices and Intro to Titanium

module.exports

Page 30: Javascript Best Practices and Intro to Titanium

Thank You!!!

Any questions…?