Click here to Skip to main content
15,896,425 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Posted
Updated 14-May-16 9:13am
Comments
Sergey Alexandrovich Kryukov 14-May-16 14:46pm    
There is no such thing as "java script".
This is not just incorrect spelling, because there is such thing as "Java", totally unrelated to "JavaScript".
—SA
girishmeena 14-May-16 14:48pm    
yes it was giving me error when writing "javascript" not in "java script"

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[^].
 
Share this answer
 
Comments
girishmeena 14-May-16 13:49pm    
You are my hero :)
CPallini 14-May-16 15:13pm    
You are welcome.
Sergey Alexandrovich Kryukov 14-May-16 14:56pm    
Carlo,

Unfortunately, I did not find a complete correct answer on the page you referenced.
There are some reasonable points in some of those answers, but all of them have some mistakes, and many of them are plain stupid. Anyway, you did not comment on any particular "answer" from that page.

The correct answer would be something like:
The question, as you, Carlo, re-formulated it, does not makes sense for JavaScript, by one simple reason: there is no OOP inheritance in JavaScript, so there is no predefined hierarchy. You should not be confused by existing hierarchy. For example, HTML DOM API implementation is based on hierarchy of objects. Also, there are many manuals on how to create an hierarchy using prototypes and/or constructors. You have to understand that it only mimics some OOP traits and is not OOP by its nature. Even though some hierarchies exist, it does not mean that there is a predefined hierarchy. The answer to the question is plain "no".

I think your guess about inquirer's thinking is correct, but strictly speaking, the question is simply incorrect. I'll add some ideaс in my Solution 2.

Probably all these discussions is the result of this: JavaScript it the World's Most Misunderstood Programming Language. I added some links on this topic in Solution 2.

—SA
CPallini 14-May-16 15:21pm    
Well, for sure, I have to admit my total ignorance of Javascript.
Sergey Alexandrovich Kryukov 14-May-16 15:29pm    
:-( :-)
I get to the depths only recently, circa 1915 (after using it for years without having deep understanding) and must admit it took good deal of thinking. In part, it is related to... high popularity of the language: there are too many articles and post from people who can use it somehow but don't have a clue on how it really works. And they try to teach wrong conceptions. I found that Mozilla MDN provides most accurate description, but even there you can find a bit of misleading material...
—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
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900