Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Apparently, there are some resemblance between objects in JavaScript and dictionaries in Python. Each language defines an object a little different (and there is some logic that all definitions to be the same as in physics).

How are objects alike and how do they differ between JavaSscript, Python and PHP?

share|improve this question

closed as too broad by gnat, GlenH7, MichaelT, Snowman, Kilian Foth Aug 29 '14 at 13:22

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

I'm not exactly sure what you are trying to get at - does Why many programming languages have only 2 data-structures: arrays and hashes? address what you are asking? – user40980 Sep 20 '13 at 14:05
how is this any different from human languages? Sure there are commonalities, but you basically just said, "I like all definitions to be the same... how come word for 'chair' is different in every language?"... maybe because it is what it is? – DXM Sep 20 '13 at 14:05
are they? I am asking what is precisely the difference between the objects definitions in those languages syntax-wise and in the real application into the machine primitives storage – sivi Sep 20 '13 at 14:08
the syntax in languages in Latin is virtually the same. maybe this differences are just a time hazzard because those language exist for a very short time. really i don't know i try to understand it too – sivi Sep 20 '13 at 14:11
... interesting and learn it, rather than try to look at 5+ of them to determine what the common denominator is. Once you learn one and then switch over to the other one, the common denominator part will become clear to you without even having to think about it. – DXM Sep 20 '13 at 15:07
up vote 6 down vote accepted

Objects really represent the same thing in all three languages: a bundling of state and operations. What truly differs is their implementation of this idea.

The largest difference is that Python & PHP are class-based object-oriented systems, meaning that the "templates" for objects are pre-defined. When a new intance of one of these templates or classes is initialized, the class's pattern or definition is used to shape the newly initialized object.

In JavaScript, the object system is prototype based. Rather than having some definition as to how objects of the same type ought to be defined and initialized, JavaScript takes a special object, a prototype, and clones it to create a new instance of that class.

All three languages are dynamic, which sets them apart from the C#/Java ecosystem in that you still have a good deal more flexibility. In JavaScript, Python and PHP you can dynamically add new properties and even functions at runtime whereas this is not truly possible in C#/Java.

See the following links for more information:

share|improve this answer
thanks great input – sivi Sep 20 '13 at 21:04
I disagree. Object-Orientation is fundamentally about Data Abstraction, more precisely Procedural Data Abstraction. Inheritance is completely orthogonal. You can have OO without inheritance and you can have inheritance without OO. And how this Data Abstraction is achieved is fundamentally different between JavaScript and Python & PHP. In Python & PHP, Data Abstraction is provided by Objects, in JavaScript, it is provided by Functions (more precisely: Closures). Really, JS objects aren't objects, they are dictionaries. Objects are implemented using JS objects + Closures. – Jörg W Mittag Sep 21 '13 at 3:53
i would love to read more of your and other points of view of this issue – sivi Sep 21 '13 at 10:41
Dictionaries and arrays are distinct types in Python while in JavaScript, dictionaries and arrays are just objects with prototypes already defined for you. You can add arbitrary properties to an JavaScript Array. You cannot in Python. – Steven Burnap Sep 22 '13 at 17:44
You can sort of do this in C# as well with ExpandoObject:… (also the name is just awesome :P) – Shivan Dragon Sep 23 '13 at 15:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.