<!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD"><HTML> <Head> <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /> <title>Untitled Document</title> <Scripttype=text/javascriptCharSet=utf-8src=.. /commons/commonutil.js></Script> <Script> //Combination Mode /** Scene Simulation: * Company *--Finance Department * Zhang San *, Zhang Yi * * and Sales department *, Zhang Four *-five * Six * * The actual task is to implement the implementation of people to implement that is only talent with a concrete way to achieve * */ varOrg= function(name) { This. Name=name; This. Depts= [] ; }; Org.prototype={constructor:org, adddepts:function(child) {//Parameter does not write data type This. Depts.push (child);//This is generally referred to as the Org object return This ; }, Getdepts:function(){ return This. depts; } }; varDept= function(name) { This. Name=name; This. Persons= [] ; }; Dept.prototype={constructor:dept, addpersons:function(child) { This. Persons.push (child); return This ; }, Getpersons:function(){ return This. Persons; } }; var Person= function(name) { This. Name=name; }; Person.prototype={Constructor:person, hardworking:function() {document.write ( This. Name+ '... Work hard!'); }, Sleeping:function() {document.write ( This. Name+ '... Try to sleep!'); } }; varP1= NewPerson ('Zhang 1'); varP2= NewPerson ('Zhang 2'); varP3= NewPerson ('Zhang 3'); varP4= NewPerson ('Zhang 4'); varP5= NewPerson ('Zhang 5'); varP6= NewPerson ('Zhang 6'); vardept1= NewDept ('Development Department'); Dept1.addpersons (p1). Addpersons (p2). Addpersons (p3); varDept2= NewDept ('Sales Department'); Dept2.addpersons (P4). Addpersons (P5). Addpersons (P6); varorg= NewOrg ('BJSXT'); Org.adddepts (DEPT1). adddepts (DEPT2); //Requirements: specifically let a person (Zhang 3) to work hard //org.getdepts ()org.hardworking ('Development Department'); for(varI= 0, Depts=org.getdepts (); I<Depts.length;i++ ){//The data type is also not written in the For Loop for(varJ= 0, Persons=depts[i].getpersons (); J<Persons.length; J++){ if(Persons[j].name=== 'Zhang 6') {persons[j].hardworking (); } } } </Script> </Head> <Body> </Body></HTML>
JS---26 combination mode