简体   繁体   English

JavaScript中的OOP,JavaScript对象属于什么类?

[英]OOP in JavaScript, what class do JavaScript objects belong to?

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.. 当我查看JavaScript对象时,例如Date对象或Time对象。

What class for example does the Date Object belong to? 例如,日期对象属于什么类?

In Javascript, there is no concept of class as in case of other programming languages. 在Javascript中,没有像其他编程语言一样的class概念。

But, we can implement OOP in Javascript through prototypes . 但是,我们可以通过prototypes在Javascript中实现OOP

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. 原型是一种我们可以在函数中定义方法和属性的方法,然后可以由使用new关键字创建的对象继承。

For better understanding, I will suggest to go through the below link. 为了更好地理解,我建议您通过以下链接。 http://javascriptissexy.com/javascript-prototype-in-plain-detailed-language/ http://javascriptissexy.com/javascript-prototype-in​​-plain-detailed-language/

JavaScript does not use classical class-based inheritance, but prototyped inheritance. JavaScript不使用经典的基于类的继承,而是原型继承。 A Date object "inherits" from Date.prototype , which is the closest thing to the object you are looking for. Date对象继承自Date.prototype Date对象,这是与您要查找的对象最接近的对象。

See: 看到:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM