KEMBAR78
Object Oriented JS | PPT
London, 20 December, 2012 | | 1
Object Oriented Javascript
What is Object-Oriented Javascript?


1. Object-oriented javascript has the capabilities of the
   object-orient programming like abstractions,
   encapsulations and inheritance.

2. Functions are objects with the capacity to hold
   executable code and pass like any other object.
Naming conventions used in JS


• Case order is : lowercase followed camel case eg:
  displayName

• Meaningful and complete names.

• Proper spacing and new line between each object
  defined. The unit of indentation is four spaces.
<function name>:<space>function<space>()<space>{

}

displayName: function () {

}

More details: http://confluence.lbi.co.uk/display/FP/JS+conventions+guide
How to use?


var LBI = window.LBI || {}; // object created here

LBI.person = { //namespace as person which encapsulates displayName and displayAge methods

            var personName, personAge

            displayName: function (name)        {

                         personName = name; //business logic

                        console.log(“ My name is ” + personName);

            },

            // this is the newline which delimits two objects

            displayAge: function(age) {

                        personAge = age; //business logic

                         console.log(“ My age is ” + personAge );

            }

}
How to use?

Function call can be made like this:

LBI.person.displayName(“xyz”);

LBI.person. displayAge(“22”);
Why it is useful?


1. It helps data and methods that operate on that data to
   encapsulate together as one object.

2. Promotes greater flexibility and maintainability.

3. Easy to develop and has strong emphasis on
   modularity.

4. Modularity promotes caching.

5. Behaviour can be re-used. (like an inheritance in oops)
End

Object Oriented JS

  • 1.
  • 2.
  • 3.
    What is Object-OrientedJavascript? 1. Object-oriented javascript has the capabilities of the object-orient programming like abstractions, encapsulations and inheritance. 2. Functions are objects with the capacity to hold executable code and pass like any other object.
  • 4.
    Naming conventions usedin JS • Case order is : lowercase followed camel case eg: displayName • Meaningful and complete names. • Proper spacing and new line between each object defined. The unit of indentation is four spaces. <function name>:<space>function<space>()<space>{ } displayName: function () { } More details: http://confluence.lbi.co.uk/display/FP/JS+conventions+guide
  • 5.
    How to use? varLBI = window.LBI || {}; // object created here LBI.person = { //namespace as person which encapsulates displayName and displayAge methods var personName, personAge displayName: function (name) { personName = name; //business logic console.log(“ My name is ” + personName); }, // this is the newline which delimits two objects displayAge: function(age) { personAge = age; //business logic console.log(“ My age is ” + personAge ); } }
  • 6.
    How to use? Functioncall can be made like this: LBI.person.displayName(“xyz”); LBI.person. displayAge(“22”);
  • 7.
    Why it isuseful? 1. It helps data and methods that operate on that data to encapsulate together as one object. 2. Promotes greater flexibility and maintainability. 3. Easy to develop and has strong emphasis on modularity. 4. Modularity promotes caching. 5. Behaviour can be re-used. (like an inheritance in oops)
  • 8.