Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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 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.

1  
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? –  MichaelT 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
    
@sivi - you can still run with that analogy. Latin is the root of all languages just like concept of objects also has common roots. But then every country (i.e. community that developed a particular language) saw a need to tweak some definitions/spellings here and there. They do it because a) they might see they have some kind of special need; b) because maybe they didn't like Latin all that much to begin with and always thought it could be done better; c) because they had to do something and simply picked a syntax and went with it. I'd say just pick a specific language that you find... –  DXM Sep 20 '13 at 15:07

1 Answer 1

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
6  
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
1  
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
1  
You can sort of do this in C# as well with ExpandoObject: msdn.microsoft.com/en-us/library/… (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.