什么是java脚本中的基类? [英] What is base class in java script ?

查看:168
本文介绍了什么是java脚本中的基类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在java脚本语言中有任何基类/对象吗?喜欢c#有System.Object。



谢谢



我尝试了什么:



我为谷歌做了但没找到任何答案。

Do we have any base class/ object in java script language? like c# has System.Object.

Thanks

What I have tried:

I did google for it but not able to find any answer.

推荐答案

我想你真的想知道 Javascript 是否有一个带根的类层次为 .NET

在我看来,这个页面提供了见解:在JavaScript中,什么是最终的根,对象或功能? - 堆栈溢出 [ ^ ]。
I suppose you are actually wondering if Javascript has a single rooted class hierachy as .NET.
In my opinion, this page gives insight: In JavaScript, what is the ultimate root, Object or Function? - Stack Overflow[^].


我冒着暴力向下回答这个答案,但事实更为重要。我会试着去争论。答案是:不,没有这样的事情。



我的大部分论点都可以在我对解决方案1的评论中找到,但并非全部。



是否有基类/对象?不,这些实际上是两个不同的问题。没有基类这样的东西,因为没有类,也没有完全类似于OOP类。并且没有基础对象这样的东西,因为没有JavaScript对象的继承这样的东西。



不要误会我的意思。使用JavaScript,人们确实创建了一些层次结构。但是这些层次结构并不像.NET那样内在。 JavaScript的工作方式非常不同。基于原型和/或构造函数的层次结构仅在功能上类似于层次结构,但在性质上完全不同。更重要的是,类型的概念是如此不同,将JavaScript类型的概念视为一种强类型语言是错误的。您可以了解类型的来源,例如,此描述:

typeof - JavaScript | MDN [ ^ ],

JavaScript数据类型和数据结构 - JavaScript | MDN [ ^ ]。



如果是.NET,事情根本就不同了。甚至原始类型(如字符或整数)也派生自 System.Object 。但它们是通过拳击以扭曲的方式衍生出来的。这是一个完全独立的主题。在JavaScript中没有类似的东西,甚至没有。但更重要的是要理解即使是对象类型也没有预定义的继承,派生或是关系的基础。甚至没有关闭。



也许你必须了解的关于JavaScripts的最重要的事情是:1)JavaScript是世界上最容易被误解的语言; 2)你不应该因为看似OOP和JavaScript之间的相似性而分心。请参阅:

JavaScript:世界上最容易被误解的编程语言 [ ^ ],

Douglas Crockford撰写的世界上最容易被误解的编程语言 [ ^ ],

JS对象:分心 [ ^ ]。



-SA
I'm risking to get violent down-votes to this answer, but the truth is more important. I'll try to argument. The answer is: no, there is no such thing.

Most of my arguments can be found in my comment to Solution 1, but that's not all.

Is there a base class/object? No. These are actually two different questions. There is no such thing as base class, because there are no classes, and nothing fully analogous to OOP classes. And there is no such thing as "base object" because there is no such thing as inheritance for JavaScript objects.

Don't get me wrong. With JavaScript, people do create some hierarchies. But those hierarchies are not something intrinsic like in .NET. JavaScript works in very, very different ways. The hierarchies based on prototypes and/or constructors are only functionally similar to class hierarchies, but are totally different in nature. More importantly, the concept of "type" is so different, that it would be wrong to consider the concept of JavaScript "type" as a type of a strongly-typed language. You can understand what a type is from, say, this description:
typeof — JavaScript | MDN[^],
JavaScript data types and data structures — JavaScript | MDN[^].

If .NET, things are fundamentally different. Even the primitive types, such as character or integer, are derived from System.Object. But they are derived in a twisted way, through boxing. This is a whole big separate topic. There is nothing like that in JavaScript, not even close. But it's more important to understand that even the "object" types have no predefined "inherit", "derived" or "is the base of" relationships. Not even close.

Perhaps most important things you have to understand about JavaScripts are: 1) JavaScript is the world's most misunderstood language; 2) you should not be distracted by seeming similarities between OOP and JavaScript. Please see:
JavaScript: The World's Most Misunderstood Programming Language[^],
The World's Most Misunderstood Programming Language by Douglas Crockford[^],
JS Objects: Distractions[^].

—SA


这篇关于什么是java脚本中的基类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆