The object orientation here mainly uses the prototype attribute. For details, refer.
<Script language = "javascript"> <! -- Function Lecture (name, teacher) {this. name = name; this. teacher = teacher;} Lecture. prototype. display = function () {return this. teacher + "teaching kindergarten" + this. name + "\ n";} function Schedule (lectures) {this. lectures = lectures;} Schedule. prototype. display = function () {var str = ""; for (var I = 0; I <this. lectures. length; I ++) {str + = this. lectures [I]. display ();} return str;} var mySchedule = new Schedule ([new Lecture ("", ""), new Lecture (" ", "Mr. Zhong")]); alert (mySchedule. display (); // --> script
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
JavaScript Object-Oriented Programming
Http://www.jb51.net/article/13661.htm