SlideShare a Scribd company logo
PBO
Object & Class Implementation on Javascript
(Pertemuan 3)
PBO (Javascript)
• An Object is a unique entity that
contains properties and methods. For example “car” is a real
life Object, which has some characteristics like color, type,
model, horsepower and performs certain actions like drive. The
characteristics of an Object are called Properties in Object-
Oriented Programming and the actions are called methods. An
Object is an instance of a class. Objects are everywhere in
JavaScript, almost every element is an Object whether it is a
function, array, or string
• A Method in javascript is a property of an object whose value is
a function
PBO (Javascript)
• Object can be created in three ways in JavaScript:
• Using an Object Literal
• Using an Object Constructor
• Using Object.create() method
PBO (Javascript)
• Using an Object
Literal
let person = {
first_name:'Mukul',
last_name: 'Latiyan',
//method
getFunction : function(){
return (`The name of the person is
${person.first_name} ${person.last_name}`)
},
//object within object
phone_number : {
mobile:'12345',
landline:'6789'
}
}
console.log(person.getFunction());
console.log(person.phone_number.landline);
PBO (Javascript)
• Using an Object
Constructor
function person(first_name,last_name){
this.first_name = first_name;
this.last_name = last_name;
}
//creating new instances of person object
let person1 = new person('Mukul','Latiyan');
let person2 = new person('Rahul','Avasthi');
console.log(person1.first_name);
console.log(`${person2.first_name}
${person2.last_name}`);
PBO (Javascript)
• Using Object.create()
method
const coder = {
isStudying : false,
printIntroduction : function(){
console.log(`My name is ${this.name}. Am I
studying?: ${this.isStudying}.`)
}
}
// Object.create() method
const me = Object.create(coder);
// "name" is a property set on "me", but not on "coder"
me.name = 'Mukul';
// Inherited properties can be overwritten
me.isStudying = true;
me.printIntroduction();
ES6 VS Traditional Object
class Vehicle {
constructor(name, maker, engine) {
this.name = name;
this.maker = maker;
this.engine = engine;
}
getDetails(){
return (`The name of the bike is ${this.name}.`)
}
}
// Making object with the help of the constructor
let bike1 = new Vehicle('Hayabusa', 'Suzuki', '1340cc');
let bike2 = new Vehicle('Ninja', 'Kawasaki', '998cc');
console.log(bike1.name); // Hayabusa
console.log(bike2.maker); // Kawasaki
console.log(bike1.getDetails());
function Vehicle(name,maker,engine){
this.name = name,
this.maker = maker,
this.engine = engine
};
Vehicle.prototype.getDetails = function(){
console.log('The name of the bike is '+ this.name);
}
let bike1 = new Vehicle('Hayabusa','Suzuki','1340cc');
let bike2 = new Vehicle('Ninja','Kawasaki','998cc');
console.log(bike1.name);
console.log(bike2.maker);
console.log(bike1.getDetails());
ENCAPSULATION
Sometimes encapsulation refers to
the hiding of data or data
Abstraction which means
representing essential features
hiding the background detail. Most
of the OOP languages provide
access modifiers to restrict the
scope of a variable, but their are no
such access modifiers in JavaScript
but there are certain ways by which
we can restrict the scope of
variables within the Class/Object
function person(fname,lname){
let firstname = fname;
let lastname = lname;
let getDetails_noaccess = function(){
return (`First name is: ${firstname} Last
name is: ${lastname}`);
}
this.getDetails_access = function(){
return (`First name is: ${firstname}, Last
name is: ${lastname}`);
}
}
let person1 = new person('Mukul','Latiyan');
console.log(person1.firstname);
console.log(person1.getDetails_noaccess);
console.log(person1.getDetails_access());
Inheritance
It is a concept in which some properties
and methods of an Object are being
used by another Object. Unlike most of
the OOP languages where classes
inherit classes, JavaScript Objects
inherit Objects i.e. certain features
(property and methods) of one object
can be reused by other Objects
Inheritance
It is a concept in which some
properties and methods of an
Object are being used by another
Object. Unlike most of the OOP
languages where classes inherit
classes, JavaScript Objects inherit
Objects i.e. certain features
(property and methods) of one
object can be reused by other
Objects
class person{
constructor(name){
this.name = name;
}
//method to return the string
toString(){
return (`Name of person: ${this.name}`);
}
}
class student extends person{
constructor(name,id){
//super keyword for calling the above class constructor
super(name);
this.id = id;
}
toString(){
return (`${super.toString()},Student ID: ${this.id}`);
}
}
let student1 = new student('Mukul',22);
console.log(student1.toString());

More Related Content

Similar to pert.3&4.pptx

JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)
Piyush Katariya
 
Kick start with j query
Kick start with j queryKick start with j query
Kick start with j query
Md. Ziaul Haq
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
David Padbury
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
 

Similar to pert.3&4.pptx (20)

jQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyjQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journey
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
How AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design PatternsHow AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design Patterns
 
Javascript coding-and-design-patterns
Javascript coding-and-design-patternsJavascript coding-and-design-patterns
Javascript coding-and-design-patterns
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)
 
Protocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftProtocol-Oriented Programming in Swift
Protocol-Oriented Programming in Swift
 
EcmaScript 6 - The future is here
EcmaScript 6 - The future is hereEcmaScript 6 - The future is here
EcmaScript 6 - The future is here
 
JavaScript Core
JavaScript CoreJavaScript Core
JavaScript Core
 
Javascript essential-pattern
Javascript essential-patternJavascript essential-pattern
Javascript essential-pattern
 
J query
J queryJ query
J query
 
Node Architecture and Getting Started with Express
Node Architecture and Getting Started with ExpressNode Architecture and Getting Started with Express
Node Architecture and Getting Started with Express
 
Kick start with j query
Kick start with j queryKick start with j query
Kick start with j query
 
Week3
Week3Week3
Week3
 
MFF UK - Introduction to iOS
MFF UK - Introduction to iOSMFF UK - Introduction to iOS
MFF UK - Introduction to iOS
 
Minimizing Decision Fatigue to Improve Team Productivity
Minimizing Decision Fatigue to Improve Team ProductivityMinimizing Decision Fatigue to Improve Team Productivity
Minimizing Decision Fatigue to Improve Team Productivity
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Greach 2019 - Creating Micronaut Configurations
Greach 2019 - Creating Micronaut ConfigurationsGreach 2019 - Creating Micronaut Configurations
Greach 2019 - Creating Micronaut Configurations
 
Revolution or Evolution in Page Object
Revolution or Evolution in Page ObjectRevolution or Evolution in Page Object
Revolution or Evolution in Page Object
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 

Recently uploaded

Transforming Brand Perception and Boosting Profitability
Transforming Brand Perception and Boosting ProfitabilityTransforming Brand Perception and Boosting Profitability
Transforming Brand Perception and Boosting Profitability
aaryangarg12
 
National-Learning-Camp 2024 deped....pptx
National-Learning-Camp 2024 deped....pptxNational-Learning-Camp 2024 deped....pptx
National-Learning-Camp 2024 deped....pptx
AlecAnidul
 

Recently uploaded (13)

The Evolution of Fashion Trends: History to Fashion
The Evolution of Fashion Trends: History to FashionThe Evolution of Fashion Trends: History to Fashion
The Evolution of Fashion Trends: History to Fashion
 
Art Nouveau Movement Presentation for Art History.
Art Nouveau Movement Presentation for Art History.Art Nouveau Movement Presentation for Art History.
Art Nouveau Movement Presentation for Art History.
 
Top Israeli Products and Brands - Plan it israel.pdf
Top Israeli Products and Brands - Plan it israel.pdfTop Israeli Products and Brands - Plan it israel.pdf
Top Israeli Products and Brands - Plan it israel.pdf
 
Transforming Brand Perception and Boosting Profitability
Transforming Brand Perception and Boosting ProfitabilityTransforming Brand Perception and Boosting Profitability
Transforming Brand Perception and Boosting Profitability
 
Expert Accessory Dwelling Unit (ADU) Drafting Services
Expert Accessory Dwelling Unit (ADU) Drafting ServicesExpert Accessory Dwelling Unit (ADU) Drafting Services
Expert Accessory Dwelling Unit (ADU) Drafting Services
 
The Design Code Google Developer Student Club.pptx
The Design Code Google Developer Student Club.pptxThe Design Code Google Developer Student Club.pptx
The Design Code Google Developer Student Club.pptx
 
Borys Sutkowski portfolio interior design
Borys Sutkowski portfolio interior designBorys Sutkowski portfolio interior design
Borys Sutkowski portfolio interior design
 
PORTFOLIO FABIANA VILLANI ARCHITECTURE.pdf
PORTFOLIO FABIANA VILLANI ARCHITECTURE.pdfPORTFOLIO FABIANA VILLANI ARCHITECTURE.pdf
PORTFOLIO FABIANA VILLANI ARCHITECTURE.pdf
 
Top 5 Indian Style Modular Kitchen Designs
Top 5 Indian Style Modular Kitchen DesignsTop 5 Indian Style Modular Kitchen Designs
Top 5 Indian Style Modular Kitchen Designs
 
National-Learning-Camp 2024 deped....pptx
National-Learning-Camp 2024 deped....pptxNational-Learning-Camp 2024 deped....pptx
National-Learning-Camp 2024 deped....pptx
 
CA OFFICE office office office _VIEWS.pdf
CA OFFICE office office office _VIEWS.pdfCA OFFICE office office office _VIEWS.pdf
CA OFFICE office office office _VIEWS.pdf
 
Book Formatting: Quality Control Checks for Designers
Book Formatting: Quality Control Checks for DesignersBook Formatting: Quality Control Checks for Designers
Book Formatting: Quality Control Checks for Designers
 
Common Designing Mistakes and How to avoid them
Common Designing Mistakes and How to avoid themCommon Designing Mistakes and How to avoid them
Common Designing Mistakes and How to avoid them
 

pert.3&4.pptx

  • 1. PBO Object & Class Implementation on Javascript (Pertemuan 3)
  • 2. PBO (Javascript) • An Object is a unique entity that contains properties and methods. For example “car” is a real life Object, which has some characteristics like color, type, model, horsepower and performs certain actions like drive. The characteristics of an Object are called Properties in Object- Oriented Programming and the actions are called methods. An Object is an instance of a class. Objects are everywhere in JavaScript, almost every element is an Object whether it is a function, array, or string • A Method in javascript is a property of an object whose value is a function
  • 3. PBO (Javascript) • Object can be created in three ways in JavaScript: • Using an Object Literal • Using an Object Constructor • Using Object.create() method
  • 4. PBO (Javascript) • Using an Object Literal let person = { first_name:'Mukul', last_name: 'Latiyan', //method getFunction : function(){ return (`The name of the person is ${person.first_name} ${person.last_name}`) }, //object within object phone_number : { mobile:'12345', landline:'6789' } } console.log(person.getFunction()); console.log(person.phone_number.landline);
  • 5. PBO (Javascript) • Using an Object Constructor function person(first_name,last_name){ this.first_name = first_name; this.last_name = last_name; } //creating new instances of person object let person1 = new person('Mukul','Latiyan'); let person2 = new person('Rahul','Avasthi'); console.log(person1.first_name); console.log(`${person2.first_name} ${person2.last_name}`);
  • 6. PBO (Javascript) • Using Object.create() method const coder = { isStudying : false, printIntroduction : function(){ console.log(`My name is ${this.name}. Am I studying?: ${this.isStudying}.`) } } // Object.create() method const me = Object.create(coder); // "name" is a property set on "me", but not on "coder" me.name = 'Mukul'; // Inherited properties can be overwritten me.isStudying = true; me.printIntroduction();
  • 7. ES6 VS Traditional Object class Vehicle { constructor(name, maker, engine) { this.name = name; this.maker = maker; this.engine = engine; } getDetails(){ return (`The name of the bike is ${this.name}.`) } } // Making object with the help of the constructor let bike1 = new Vehicle('Hayabusa', 'Suzuki', '1340cc'); let bike2 = new Vehicle('Ninja', 'Kawasaki', '998cc'); console.log(bike1.name); // Hayabusa console.log(bike2.maker); // Kawasaki console.log(bike1.getDetails()); function Vehicle(name,maker,engine){ this.name = name, this.maker = maker, this.engine = engine }; Vehicle.prototype.getDetails = function(){ console.log('The name of the bike is '+ this.name); } let bike1 = new Vehicle('Hayabusa','Suzuki','1340cc'); let bike2 = new Vehicle('Ninja','Kawasaki','998cc'); console.log(bike1.name); console.log(bike2.maker); console.log(bike1.getDetails());
  • 8. ENCAPSULATION Sometimes encapsulation refers to the hiding of data or data Abstraction which means representing essential features hiding the background detail. Most of the OOP languages provide access modifiers to restrict the scope of a variable, but their are no such access modifiers in JavaScript but there are certain ways by which we can restrict the scope of variables within the Class/Object function person(fname,lname){ let firstname = fname; let lastname = lname; let getDetails_noaccess = function(){ return (`First name is: ${firstname} Last name is: ${lastname}`); } this.getDetails_access = function(){ return (`First name is: ${firstname}, Last name is: ${lastname}`); } } let person1 = new person('Mukul','Latiyan'); console.log(person1.firstname); console.log(person1.getDetails_noaccess); console.log(person1.getDetails_access());
  • 9. Inheritance It is a concept in which some properties and methods of an Object are being used by another Object. Unlike most of the OOP languages where classes inherit classes, JavaScript Objects inherit Objects i.e. certain features (property and methods) of one object can be reused by other Objects
  • 10. Inheritance It is a concept in which some properties and methods of an Object are being used by another Object. Unlike most of the OOP languages where classes inherit classes, JavaScript Objects inherit Objects i.e. certain features (property and methods) of one object can be reused by other Objects class person{ constructor(name){ this.name = name; } //method to return the string toString(){ return (`Name of person: ${this.name}`); } } class student extends person{ constructor(name,id){ //super keyword for calling the above class constructor super(name); this.id = id; } toString(){ return (`${super.toString()},Student ID: ${this.id}`); } } let student1 = new student('Mukul',22); console.log(student1.toString());