Class is in Session


#1

HI ,
i never understand it ,even i passed the lesson
this.name=name;
this.age=age;
why we need to do this ?
i ever donot understand it .thanks


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

// Let's make bob again, using our constructor
var bob = new Person("Bob Smith", 30);
var susan = new Person("Susan Jordan", 35);

// make your own class here
function Circle(radius){
    this.radius=radius;}
    var radius=new Circle(90)

#2

Is this function Person inside a class or is it just alone?


#3

Nothing :grinning: didn’t see the title


#4

Is the class called Person?


#5

yes, it is in the class


#7

yes ,could you explain one time .thanks


#8

The reason you use this.key is because that is how you assign values inside of a constructor. When you call the constructor, with bob, or susan, you can pass their names and ages. It creates the objects, and uses this.key to say “this objects name is equal to the name variable” or “this objects age is equal to the age variable”

it allows you to create dozens of objects of the same class, while giving them different values to make them unique

this is a terrible explanation, but i can try to explain it more in depth if you need me to


#9

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