![]() |
#1 |
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. |
![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
![]() |
||||
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 |