Go Back   Site Owners Forums - Webmaster Forums > Web Programming > Programming General

Notices


 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
Old 03-10-2023, 07:52 AM   #1
sahithya
Registered User
 
Join Date: Feb 2013
Location: Bangalore
Posts: 1,229
Class in Javascript (OOP)

Class is a blueprint for creating objects that share a similar structure and behavior.
It defines a set of properties and methods that will be inherited by the objects instantiated from it.

The class keyword was introduced in ES6 as a syntactical sugar to facilitate the creation of object-oriented code.

In the example, we have defined a Car class with a constructor that takes make, model, and year parameters. These parameters are used to initialize the instance variables of the object.

We have also defined a drive method that will be inherited by all objects instantiated from the Car class. The drive method logs a message to the console with the make and model of the car.

To create an object from the Car class, we can use the new keyword and call the Car constructor.
This will create a new Car object with the make 'Audi', model 'A4', and year 2016.

We can then call the drive method on this object.
This will log the message “Driving the Audi A4” in the console.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
sahithya is offline   Reply With Quote

 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
On BeEducated.pk View Your 10th Class Result 2018 in July nazimalik Post your ad here 2 07-10-2018 05:12 AM
what is javascript ehsanagar Javascript 6 04-18-2017 03:48 AM
Best Shared SEO Hosting Plans at Best Price with Best Features | RankFirstHosting.Com rf-harris Post your ad here 0 12-30-2015 06:31 AM
How to Implement Interfaces in JavaScript JavaScriptBank Javascript 1 03-30-2014 11:48 PM
Javascript Countdown Timer redirecting Affiliate Links JavaScriptBank Javascript 0 05-20-2013 10:29 PM


All times are GMT -7. The time now is 11:29 PM.


Powered by vBulletin Copyright © 2020 vBulletin Solutions, Inc.