0% found this document useful (0 votes)
4 views5 pages

JavaScript OOP and Transformer Examples

Uploaded by

arpanarpan43376
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

JavaScript OOP and Transformer Examples

Uploaded by

arpanarpan43376
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JavaScript Transformers and OOP Examples

[Link]
class User {
constructor(username){
[Link] = username
}

logMe(){
[Link](`Username: ${[Link]}`);
}

static createId(){
return `123`
}
}

const hitesh = new User("hitesh")


class Teacher extends User {
constructor(username, email){
super(username)
[Link] = email
}
}
const iphone = new Teacher("iphone", "i@[Link]")
[Link]([Link]());

properties_get_set.js
function User(email, password){
this._email = email;
this._password = password

[Link](this, 'email', {
get: function(){
return this._email.toUpperCase()
},
set: function(value){
this._email = value
}
})
[Link](this, 'password', {
get: function(){
return this._password.toUpperCase()
},
set: function(value){
this._password = value
}
})
}
const chai = new User("chai@[Link]", "chai")
[Link]([Link]);

[Link]
const user = {
username: "hitesh",
loginCount: 8,
signedIn: true,
getUserDetails: function(){
[Link](this);
}
}
function User(username, loginCount, isLoggedIn){
[Link] = username;
[Link] = loginCount;
[Link] = isLoggedIn
[Link] = function(){
[Link](`Welcome ${[Link]}`);
}
return this
}
const userOne = new User("hitesh", 12, true)
const userTwo = new User("ChaiAurCode", 11, false)
[Link]([Link]);

object_get_set.js
const User = {
_email: 'h@[Link]',
_password: "abc",
get email(){
return this._email.toUpperCase()
},
set email(value){
this._email = value
}
}
const tea = [Link](User)
[Link]([Link]);

[Link]
# javascript and classes
## OOP
## Object
- collection of properties and methods
- toLowerCase
## why use OOP
## parts of OOP
Object literal
- Constructor function
- Prototypes
- Classes
- Instances (new, this)
## 4 pillars
Abstraction
Encapsulation
Inheritance
Polymorphism

[Link]
class User {
constructor(username, email, password){
[Link] = username;
[Link] = email;
[Link] = password
}
encryptPassword(){
return `${[Link]}abc`
}
changeUsername(){
return `${[Link]()}`
}
}
const chai = new User("chai", "chai@[Link]", "123")
[Link]([Link]());
[Link]([Link]());
function User(username, email, password){
[Link] = username;
[Link] = email;
[Link] = password
}
[Link] = function(){
return `${[Link]}abc`
}
[Link] = function(){
return `${[Link]()}`
}
const tea = new User("tea", "tea@[Link]", "123")
[Link]([Link]());
[Link]([Link]());

[Link]
const descripter = [Link](Math, "PI")
const chai = {
name: 'ginger chai',
price: 250,
isAvailable: true,
orderChai: function(){
[Link]("chai nhi bni");
}
}
[Link]([Link](chai, "name"));
[Link](chai, 'name', {
enumerable: true,
})
[Link]([Link](chai, "name"));
for (let [key, value] of [Link](chai)) {
if (typeof value !== 'function') {
[Link](`${key} : ${value}`);
}
}

[Link]
class User {
constructor(username){
[Link] = username
}
logMe(){
[Link](`USERNAME is ${[Link]}`);
}
}
class Teacher extends User{
constructor(username, email, password){
super(username)
[Link] = email
[Link] = password
}
addCourse(){
[Link](`A new course was added by ${[Link]}`);
}
}
const chai = new Teacher("chai", "chai@[Link]", "123")
[Link]()
const masalaChai = new User("masalaChai")
[Link]()
[Link](chai instanceof User);

getter_setter.js
class User {
constructor(email, password){
[Link] = email;
[Link] = password
}
get email(){
return this._email.toUpperCase()
}
set email(value){
this._email = value
}
get password(){
return `${this._password}hitesh`
}
set password(value){
this._password = value
}
}
const hitesh = new User("h@[Link]", "abc")
[Link]([Link]);

[Link]
function SetUsername(username){
[Link] = username
[Link]("called");
}
function createUser(username, email, password){
[Link](this, username)
[Link] = email
[Link] = password
}
const chai = new createUser("chai", "chai@[Link]", "123")
[Link](chai);

You might also like