2

I'm in a beginning HTML class and our textbook says that JavaScript is an object-based scripting language. On our quiz, one of the questions was "JavaScript is an object-oriented scripting language, True or False." I put False because it's my understanding that object-based and object-oriented are two different things. I got the answer wrong.

Is JavaScript indeed an object-oriented language?

Thanks for any clarification you can give!

6
  • 3
    I would agree that calling it OO is a bit of a stretch. Commented Nov 8, 2010 at 1:40
  • 1
    Duplicate of stackoverflow.com/questions/107464/…? Commented Nov 8, 2010 at 1:41
  • It is OO, it just isn't a class based language like some may be used to, it prototype based Commented Nov 8, 2010 at 1:44
  • You should have asked your professor if O-based and OO were the same to him. Commented Nov 8, 2010 at 1:58
  • Ah, sorry, InSane. I did a search, but didn't see that thread! What I'm getting from all these responses is that the answer is pretty subjective, depending on how you interpret the wobbly definition of object-oriented programming. I wonder if I should argue with my teacher. Thank you all much for your responses! Commented Nov 8, 2010 at 9:30

9 Answers 9

9

JavaScript uses prototype-based programming, which is a type of object oriented programming. Prototypes are a way of reusing behaviors by cloning existing objects instead of doing class based inheritance. It's different enough from the standard class based object oriented programming that few people bother to learn it well enough to make good use of it.

http://en.wikipedia.org/wiki/Prototype-based_programming is a useful reference.

Sign up to request clarification or add additional context in comments.

Comments

4

The definition of Object Oriented is sometimes subjective. For some, any language that deals with "Objects", is Object Oriented. For others, the entire language and its construct must utilize objects to be counted as Object Oriented (think SmallTalk or Java).

In javascript, you're able to write a script that has no objects in it or you can create heavily object oriented code. Whether or not you call it Object Oriented is really dependant on what school of thought you follow.

2 Comments

+1, I guess whether or not the OP was right on the quiz depends on how the textbook defines these terms. Of course, the fact remains that such questions shouldn't be asked.
Writing a script with no objects in it is pretty difficult. You couldn't use any functions, and only primitive numbers, strings and arrays.
2

I'd say that object-oriented is not a feature of programming languages, it is a feature of code. Code does not grow object-oriented, prototype-based or functional simply because it is written in a specific language, it obtains such a quality only if the author use that style.

Sure, it makes sense to call a language like Java object-oriented since the language is designed specifically for that paradigm, but JavaScript works well with a load of different paradigms, so you really can't put a sticker on it.

Comments

1

This answer I am sure has been answered elsewhere.... object-based and object-orientated are the same thing, used interchangeably. There is actually no difference in the terminology - some prefer one over the other.

To answer your question, yes, Javascript is object-orientated or object-based.

10 Comments

What is the difference between object-oriented and object-orientated?
They are some subtle differences... apparently VB6 is object-based but not object-oriented because it doesn't support inheritance.
@tchrist: it's an adverb of object-base meaning object-based, likewise same for object-oriented... again, you're falling for the terminology, if you see it, think OOP which is an acronym for Object Oriented Programming, again, Oriented, Orientated... same thing... :)
tommieb75 is indeed correct, though I rarely see orientated used, it's not as common as hearing oriented but they do mean the same thing.
Since object-orientated is objectively a higher-falultin’ word, I figure it must be even objectier than plain old-fashioned run-of-the-mill object-oriented. Otherwise I object to its extra syllababble. ☺
|
1

Javascript is a superset of ECMAScript, which is a multi-paradigm ( functional, procedural ), prototype-based, functional, imperative scripting language with duck/weak/dynamic typing and is influenced by Perl, C, Python, Java, Scheme.

ECMAScript was created by Brendan Eich. Source: http://en.wikipedia.org/wiki/ECMAScript

It adopts C constructs such as if and else and for, but also has closures and lambdas from Scheme, as well as prototype-based inheritance from Self so it can be used in an OO way.

2 Comments

How the heck was ECMAScript influenced by Python or Scheme? Python is such a beautiful and productive language and ECMAScript just.... isn't and Scheme is a Lisp dialect. Code-as-data, etc. ECMAScript treats code just as a sequence of plain ASCII characters.
Python and Scheme both have closures and lambdas.. coincidentally, ECMAScript, which came after both, does as well. The syntax and constructs in Python are very similar to that of ECMAScript. You can literally copy paste some Python code and it works exactly the same in ECMAScript. So I'm not saying the entire language was copy pasted, but fundamental parts were influenced, at least.
0

Object-based, object-oriented, basically the same thing. It's my impression that object-oriented is a bit stricter than object-based.

Object-based implies that the language uses the idea of encapsulating state and operations inside "objects".

Object-oriented means that the language is designed for programming with objects.

The difference is pretty minor. See the wikipedia articles on object-based language and object-oriented programming to get a finer idea of the difference.

Comments

0

The term Object-oriented programming (OOP) is not very well-defined in general. See Jonathan Rees note on OO: Rees on OO. Javascript has an OO model based on a concept named prototypes. The prototype-based model is different from the model used in Java or C++, but it certainly falls underneath the general umbrella that is OOP-based languages.

Perhaps the term "object-based" was used to underline this fact about javascript. It uses objects, but not in the same vein as Java or C++ (or C#) does.

Comments

0

The object-oriented fundamentals are there but are structured differently from other more common object-oriented languages like C# and Java. You can create object constructors and methods, and access and retrieve object properties. JavaScript was designed to be a completely object-oriented language from the start but somehow was influenced by Perl and Python and therefore the current programmatic idioms.

What is wrong with this object-oriented notation in javascript?

function Class( name, teacher ) {
  this.name = name;
  this.teacher = teacher;
}

Comments

0

If your quiz defined neither ‘object-oriented’ nor ‘scripting language’, I can’t possibly see how you can be expected to answer the question.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.