Loading presentation...

Present Remotely

Send the link below via email or IM


Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.


Object Oriented JavaScript

No description

Nishit Sinha

on 15 September 2016

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Object Oriented JavaScript

Object Oriented JavaScript (OOJS)
Object Oriented Programming
Object, method and property
Class (We don't have it in JS)
Variables, Its kind and Operations
Functions allow you group together some code, give this code a name, and reuse it later, addressing it by name.
Feature Illustrates concept
Bob is a man (an object) object
Bob's date of birth is June 1st, 1980, gender: male, hair: black. properties
Bob can eat, sleep, drink, dream, talk and calculate his age. methods
Bob is an instance of class Programmer. class (in classical OOP)
Bob is based on another object, called Programmer. prototype (in prototypal OOP)
Bob holds data (such as birth date) and methods that work with encapsulation
the data (such as calculate age).
We don't need to know how the calculation method works information hiding
internally. The object might have some private data,
such as the number of days in February in a leap year, we don't
know, nor do we want to know.
Bob is part of a Web Dev Team object, together with Jill, a aggregation, composition
Designer object and Jack, a Project Manager object.
Designer, Project Manager and Programmer are all based on inheritance
and extend a Person object.
You can call the methods Bob:talk, Jill:talk and Jack:talk and polymorphism, method overriding
they'll all work fine, albeit producing different results (Bob will
probably talk more about performance, Jill about beauty and
Jack about deadlines). Each object inherited the method talk
from Person and customized it.
Declare the variable.
Initialize it and provide the value.
Variables are case sensitive.
Data Type
All non Primitive Data Types are Objects
+ (Addition)
- (Substraction)
* (Multiplication)
/ (Division)
% (Modulo)
-- (Decrement pre/post)
++ (Increment pre/post)
! (Logical NOT or Negation)
&& (Logical AND)
|| (Logical OR)
== (Equality Comparison)
=== (Equality and Type Comparison)
!= (Non-equality Comparison )
!== (Non-equality comparison without type conversion)
> (Greater than)
>= (Greater than Equal to)
< (Less than)
<= (Less than Equal to)
The empty string ""
The number 0
The number NaN
The boolean false
Using Double Negation on any value becomes true. With the exception of the given below things.
Any kind of grouped elements under the name of the single variable is array. It is an object.
Array Definition: var a = [1,2,3]
To Access Array: a['subscript']
Adding an element to array: a[5] = 'name';
Deleting and element from array : delete a[4];
if else
switch case
while loop
do while
for loop
for - in loop
For - in loop
The for-in loop is used to iterate over the elements of an array. This is its only use; it cannot be used as a general-purpose repetition mechanism that replaces for or while.
var a = [ 'a', 'b', 'c', 'x', 'y', 'z'];
var result = '\n';
for (var i in a) {
result += 'index: ' + i + ', value: ' + a[i] + '\n';
function sum(a, b)
var c = a + b;
return c;
Parts of a function:
The function statement
The name of the function
Expected parameters
Code block
var sum = function()
var c = a + b;
return c;
Anonymous Function and Self Invoking Function
You can pass an anonymous function as a parameter to another function. The receiving function can do something useful with the function that you pass.
You can define an anonymous function and execute it right away.
alert('Hello ' + name + '!');
CallBack Functions
Now, we have seen that functions are just data. It can be assigned to the variables. So, can we pass the function as a parameter ?
function invoke_and_add(a, b)
return a() + b();
function one() {
return 1;
function two() {
return 2;
>>invoke_and_add(one, two);
function multiplyByTwo(a, b, c, callback) {
var i, ar = [];
for(i = 0; i < 3; i++) {
ar[i] = callback(arguments[i] * 2);
return ar;
>> myarr = multiplyByTwo(1, 2, 3, function(a){return a + 1});
Inner Functions
You keep the global namespace clean (smaller chance of naming collisions).
Privacy—you expose only the functions you decide�eeeeto the "outside world", keeping to yourself functionality that is not meant to be consumed by the rest of the application.
var a = function(param)
var b = function(theinput) {
return theinput * 2;
return 'The result is ' + b(param);
function a(param)
function b(theinput) {
return theinput * 2;
return 'The result is ' + b(param);
Scope Chain
Lexical Scope
Here no curly braces scope, but there is function scope. A variable defined in a function is not visible outside the function, but a variable defined in a code block (an if or a for loop) is visible outside the block.

var a = 1;
function f()
{var b = 1; return a;}
Functions create their environment (scope) when they are defined, not when they are executed.

function f1()
{var a = 1; f2();}
function f2()
{return a;}
Closure #1
function f()
var b = "b";
return function()
return b;
Closure #2
var n;
function f()
var b = "b";
n = function()
return b;
Closure #3
function f(arg)
var n = function(){
return arg;
return n;
Full transcript