Different Ways of Creating Objects in JavaScript | Objects in JavaScript | Ways of Creating Objects

Опубликовано: 06 Январь 2022
на канале: Azhar Techno Coder
105
30

Code :
//Different Ways of Creating Objects in JavaScript | Objects in JavaScript | Ways of Creating Objects
//1. Object Constructor
//Very simple way to create an object

var simpleObject = new Object()
//console.log(typeof simpleObject)

//2. Object create method
var secondMethod = Object.create(null);
//console.log(typeof secondMethod)

//3. Object literal syntax
var thirdMethod = {}
//console.log(typeof thirdMethod)

//4. Function constructor
function fourthMethodFunction(name,sno){
this.name = name;
this.sno = sno;
}

var fourthMethod = new fourthMethodFunction("test",1)
//console.log(typeof fourthMethod)

//5. function constructor with prototype

function fifthMethodFunction(){}
fifthMethodFunction.prototype.name = "test"
fifthMethodFunction.prototype.sno = 1

var fifthMethod = new fifthMethodFunction()
//console.log(typeof fifthMethod)

//ES6 Class Syntax

class sixthMethod{
constructor(name){
this.name = name
}
}

var sixthObjectCreation = new sixthMethod("test")
//console.log(typeof sixthObjectCreation)

//Singleton pattern
var seventhObject = new function(){
this.name = "test"
}

console.log(typeof seventhObject)

Description Tags
Object Oriented JavaScript Tutorial #2 - Object Literals,Different Ways of Creating Objects in JavaScript,Ways of Creating Objects in JavaScript (),What Are Objects in JavaScript | How to Create an Object in JavaScript | JavaScript Tutorial,What are the four ways of creating an object in JavaScript,creating objects in javascript | Bhanu Priya,ways of creating objects in javascript,javascript object creation,javascript tutorials



Next Steps :

---------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------
Must Watch Playlists

► 1. Javascript -    • Javascript Factory  
► 2. Puppetter -    • Puppeteer  
► 3. Cypress -    • Cypress  
► 4. Tech works -    • Video  
► 5. Vbscript Basics To Advanced -    • VBScript Part 1 -  Features Advantage...  
► 6. Jmeter -    • Jmeter Tutorials  
► 7. Excel -    • Videos On Excel  
► 8. Appium -    • Appium  
► 9. Shares -    • Shares  
► 10. Javascript Interview Questions -   • Javascript Interview Questions  
---------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------

#Objects
#javascript
#differentwaysToCreateObjects