Objects | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Objects

//creating an objects using the OBJECT CONSTRUCTOR FUNCTION for mutiple objects: function student(name,age,classRoom) { this.name=name; this.age=age; this.classR=classRoom; //define the function INSIDE of the constructor function: this.changeName=function(stName){this.name=stName;} this.changeAge=function(stAge){this.age=stAge;} //define the function OUTSIDE of the constructor function: this.yearOfBirth=bornYear; } function bornYear(){return 2016-this.age;} var st1Obj=new student("Abdullah",47,"ClassA"); var st2Obj=new student("Abdulaziz",19,"ClassB"); st1Obj.changeName("Abdumalak"); st1Obj.changeAge(11); document.write("Name: ",st1Obj.name," ,Birth Year: ",st1Obj.yearOfBirth(),", Age: ",st1Obj.age,", Class room: ",st1Obj.classR,"<br/>"); document.write("Name: ",st2Obj.name," ,Birth Year: ",st2Obj.yearOfBirth(),", Age: ",st2Obj.age,", Class room: ",st2Obj.classR,"<br/>");

30th Oct 2016, 2:13 PM
Abdullah Ojiman Al-Qahtani
Abdullah Ojiman Al-Qahtani - avatar
1 Answer
0
what is your question?
5th Nov 2016, 8:35 PM
Birk
Birk - avatar