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!

pumkin54
  • 21
  • 1
  • 2
  • 3
    I would agree that calling it OO is a bit of a stretch. – Gabe Nov 08 '10 at 01:40
  • 1
    Duplicate of http://stackoverflow.com/questions/107464/is-javascript-object-oriented? – Jagmag Nov 08 '10 at 01:41
  • It is OO, it just isn't a class based language like some may be used to, it prototype based – DaiYoukai Nov 08 '10 at 01:44
  • You should have asked your professor if O-based and OO were the same to him. – Ben Nov 08 '10 at 01: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! – pumkin54 Nov 08 '10 at 09:30
  • The ECMA script specs have mentioned 2 different things in the following sections which makes it ambigious: [Overview](https://www.ecma-international.org/ecma-262/5.1/#sec-4) - this mentions that it "ECMAScript is an object-oriented programming language for performing computations and manipulating computational objects within ... [Language Overview](https://www.ecma-international.org/ecma-262/5.1/#sec-4.2) -this section says that "ECMAScript is object-based: basic language and host facilities are provided by objects, and an ECMAScript program is a cluster of com..... – diganta Oct 25 '17 at 09:35

9 Answers9

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.

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.

ajacian81
  • 7,419
  • 9
  • 51
  • 64
  • 4
    +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. – casablanca Nov 08 '10 at 01:46
  • Writing a script with no objects in it is pretty difficult. You couldn't use any functions, and only primitive numbers, strings and arrays. – Chuck Nov 08 '10 at 03:58
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.

aaaaaaaaaaaa
  • 3,630
  • 1
  • 24
  • 23
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.

t0mm13b
  • 34,087
  • 8
  • 78
  • 110
  • 2
    What is the difference between object-oriented and object-orientated? – tchrist Nov 08 '10 at 01:43
  • They are some subtle differences... apparently VB6 is object-based but not object-oriented because it doesn't support inheritance. – Rafe Kettler Nov 08 '10 at 01:46
  • @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... :) – t0mm13b Nov 08 '10 at 01:46
  • 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. – DaiYoukai Nov 08 '10 at 01:48
  • Well, I have to disagree. On one hand you have Smalltalk that is 100% object oriented while in the other hand you've JS that is not 100% object oriented. Same applies with Python and JS, Python is not a 100% scripting language while JS is, yet Python is often used as an scripting language. "Often used as" doesn't define a language. – Ben Nov 08 '10 at 01:53
  • 2
    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. ☺ – tchrist Nov 08 '10 at 01:54
  • @Ben, what’s a scripting language? – tchrist Nov 08 '10 at 01:58
  • @tchrist - To me, those that are interpreted. Python can be compiled, JS can't. Point is JS is a scripting language and Python isn't as Smalltalk is a OO language while JS isn't. – Ben Nov 08 '10 at 02:03
  • So Java is a scripting language, then? Or Smalltalk? I don’t see how “scripting” has any reasonable meaning, since there will always be **something** interpreting the instruction. Mostly, “scripting” gets used as a put-down by proponents of statically typed languages against dynamic languages, which they automatically disdain. – tchrist Nov 08 '10 at 02:14
  • @Ben There's nothing stopping you from compiling Javascript. *What into* is the real question. There's a [Javascript to Java compiler made by Mozilla](https://developer.mozilla.org/en/Rhino_JavaScript_Compiler). It very literally gets rid of the "script" in "Javascript"... – deceze Nov 08 '10 at 02:33
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.

meder omuraliev
  • 183,342
  • 71
  • 393
  • 434
  • 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. – Peter C Nov 09 '10 at 00:29
  • 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. – meder omuraliev Nov 09 '10 at 02:51
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.

Rafe Kettler
  • 75,757
  • 21
  • 156
  • 151
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.

I GIVE CRAP ANSWERS
  • 18,739
  • 3
  • 42
  • 47
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;
}
Srikar Doddi
  • 15,499
  • 15
  • 65
  • 106
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.

tchrist
  • 78,834
  • 30
  • 123
  • 180