Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/School-Work / School Work/What are Constructor Functions/page1.js |
| Date | Not specified in source |
| Repository | Janady13/School-Work |
| Revision | 4a666c890caf7c43c47d0572dbcc287373c7a78e |
| Branch | main |
| Path or archive member | School Work/What are Constructor Functions/page1.js |
| Original SHA-256 | 336066bb16d8e9b1b46bf3212aa623aef7c6c4ba266bda97e7bed7e0ee3f2f42 |
| Git blob SHA | a97175009439d230187a0211b65fbbcdc86c9555 |
| Reading-copy SHA-256 | 336066bb16d8e9b1b46bf3212aa623aef7c6c4ba266bda97e7bed7e0ee3f2f42 |
Recovered source transcript
Download complete source text ↓23 lines · 0.7 KB
//constructor functions
function Student(id, name, subjects = [] ){ //capitalize function because it is there to creat objects. Not an operation
this.id = id;
this.name = name;
this.subjects = subjects;
}
//can not use an arrow function.
Student.prototype.addSubject = function(subject){
this.subjects = [...this.subjects, subject]
}
//example
const student1 = new Student(060507, Joseph, "Programming") //creating a new student from the Constructor function.
const student2 = new Student(12345, Amber, "Physics")
//You can now add individual classes to each student and create students to shorten the length.
student2.addSubject("Math")
student1.addSubject("English")