-2

I am only starting to learn JavaScript and encounered with a problem trying to understand how the prorotypes work.

I got the following code

var parent = {
    city : "Cardiff",
    hair : "white",
    surname : "Smith",
    name : "John"
};

var child = Object.create(parent);{
    name : "Mike"
};

child.name

And when I call child.name it returns me John and not Mike. I tried to google, change the code, browsed through some reference books but still can't find the reason why am I returned John.

cameraobscura
  • 177
  • 1
  • 2
  • 17

1 Answers1

1
var child = Object.create(parent);{
    name : "Mike"
};

Is just

var child = Object.create(parent);

{
    name : "Mike"
};

So you create child then create some other random object with one property name whose value is "Mike".

djechlin
  • 59,258
  • 35
  • 162
  • 290