0

From my basic understanding of Object Oriented Programming, a Class is a blueprint of an Object. For example, one might say apple, oranges etc is Object of Class Fruit.

I'm not understanding the structure , please forgive the basic-ness of this question.

When I look at the JavaScript Objects, for example a Date Object, or a Time Object..

What class for example does the Date Object belong to?

Donna
  • 7
  • 6
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date –  Jul 27 '17 at 18:09
  • Yes, thank you for that reference Amy. I did pull up that link myself but still could not understand the Class that the Javascript Date Object belongs to? What is the NAME of the class that the js object belongs to? – Donna Jul 27 '17 at 18:14
  • See [Benefits of prototypal inheritance over classical?](https://stackoverflow.com/questions/2800964/benefits-of-prototypal-inheritance-over-classical/16872315#16872315). JavaScript does not use classical class-based inheritance. – trincot Jul 27 '17 at 18:14
  • @Donna .... It's the `Date` class. It doesn't "belong" to anything. –  Jul 27 '17 at 18:17
  • Cool thanks Amy and Trincot.. I am just beginning to understand the fact that Js doesn't have the concept of class.. which initially went over my head. Its Prototypes.. and I'm reading on it now from the link Anurag sent below. Thanks all! – Donna Jul 27 '17 at 18:22
  • @Donna it might be more correct to say JS has a *different* concept of "class" than other languages, rather than it doesn't have the concept at all. –  Jul 27 '17 at 18:28

2 Answers2

1

In Javascript, there is no concept of class as in case of other programming languages.

But, we can implement OOP in Javascript through prototypes.

Prototypes are a way through which we can define methods and properties in a function, which then can be inherited by objects created using the new keyword.

For better understanding, I will suggest to go through the below link. http://javascriptissexy.com/javascript-prototype-in-plain-detailed-language/

Anurag Singh Bisht
  • 2,683
  • 4
  • 20
  • 26
  • Thank you!! This might be what I am looking for. Was trying to wrap my head around .. but where is the Class for these js objects? Never heard of prototypes before but this is starting to make sense! – Donna Jul 27 '17 at 18:20
  • So basically, In javascript we don't have class. We consider one base `object` or a `function` and use it as a class for `other object` created by `new` operator or `Object.create` syntax. – Anurag Singh Bisht Jul 27 '17 at 18:22
0

JavaScript does not use classical class-based inheritance, but prototyped inheritance. A Date object "inherits" from Date.prototype, which is the closest thing to the object you are looking for.

See:

trincot
  • 317,000
  • 35
  • 244
  • 286
  • Thank you I am beginning to see it now. Literally spent the last few days determined to find the class lol. I finished a course in javascript in codeacademy then really wanted to get the basics of programming because I read that coding and programming is not the same.. then I started to go deep into the basics of programming .. classes, objects, etc.. anyway thank you for your answer! – Donna Jul 27 '17 at 18:27