| |

VerySource

 Forgot password?
 Register
Search
View: 770|Reply: 3

Help me understand this little white

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-18 09:40:02
| Show all posts |Read mode
function Employee (name, salary, mySupervisor)
{
  this.name = name;
  this.salary = salary;
  this.supervisor = mySupervisor;
}

var boss = new Employee ("111", 200);
var manager = new Employee ("222", 50, boss);
var teamLeader = new Employee ("Rose", 50, boss);
 
alert (manager.supervisor.name + "is the supervisor of" + manager.name);
alert (manager.name + "\'s supervisor is" + manager.supervisor.name);

</ script>
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-23 13:27:01
| Show all posts
manager.supervisor.name I don't understand
Reply

Use magic Report

0

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-1-23 20:27:01
| Show all posts
manager is an object of Employee, supervisor and name are attributes of Employee,
manager.supervisor is a boss object,
So manager.supervisor.name is equivalent to boss.name
While boss.name is 111 and manager.name is 222
So manager.supervisor.name is 111
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-28 14:45:02
| Show all posts
This is one way JavaScript builds classes.
Use the constructor Employee to build, which are the attributes.

The next few sentences are creating instances and showing their relationship.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list