23. Private variables


#1

I can't follow the instructions in this exercise. They seem to be asking for us to simply create a new object, but I assume that we need to make that object inherit from the object 'person', as we saw in previous exercises. Please help!

function Person(first,last,age) {
this.firstname = first;
this.lastname = last;
this.age = age;
var bankBalance = 7500;
}

function John(name, age){
this.name = name;
this.age = age;
}

john.prototype = new Person();

var john = {
name: "John",
age: 30
}


#2

You lost me at,

Just what is expected from this? What follows is even more questionable. I'm confused. Can you walk us through this, please?


#3

Well I'm mainly following syntax from the previous exercises because I'm feeling a bit lost as the instructions are vague. At first I just created a simple object:

var john = {
name: "John",
age: 30
}

because this is all the instructions ask for. But then I considered that the variable john needs to inherit from person, so I followed from syntax in the previous exercise. I think that the john function and the prototype code should enable 'john' to inherit from 'person', but this is partly guesswork because I have no structure to work with.


#4

What you have there is a plain object. Your question deals with something much more complex than that. Have we missed a step or two here?


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.