Ok am just going through basics of JavaScript and I was learning objects where I came across this example…
JavaScript
var person = {
firstname : "Smith",
lastname : "Bach"
};
And what we write in PHP is
$person = array(
"firstname"=>"Smith",
"lastname"=>"Bach"
);
So is this the same thing or am making a mistake in understanding the concept?
No, objects are more than that.
Object is indeed a map/dictionary, but additionally every object inherits some of the properties (key-value pairs) from another object. That other object is called prototype.
For example:
Most commonly a prototype is set by creating an object with a constructor function:
EDIT:
Here’s how the prototype works using constructor functions (it’s one of the ways to do OOP in JS):