View Code
1 / * ########################################### * 2 * 1 established by the object-oriented JavaScript prototype 3 inherited * 2. based on the class 4 ################################# ########## * / . 5 . 6 / * ################## 1 ############### ## * / 7 / * create a vehicle constructor * / . 8 function vehicle () { . 9 / * vehicle attribute * / 10 var wheelCounts =. 4; // number of wheels . 11 var curbWeightInPounds = 3000; // car weight 12 13 the this .getWheelCounts =function() { 14 return wheelCounts; 15 } ; 16 this.getCurbWeightInPounds = function() { 17 return curbWeightInPounds; 18 } ; 19 20 this.setWheelCounts = function(wc) { 21 wheelCounts = wc; 22 } ; 23 this.setCurbWeightInPounds = function(cwp) { 24 curbWeightInPounds = cwp; 25 } ; 26 //燃料 27 this.refueling = function() { 28 return "refueiing..."; 29 }; 30 31 //主要任务 32 this.mainTasks = function() { 33 return "Go to school, shop and so on."; 34 }; 35 36 }; 37 38 39 40 /*赛车*/ 41 function SPortsCar() { 42 43 //燃料 44 SPortsCar.prototype.refueling = function() { 45 return "SportsCar refueiing 3000" ; 46 is }; 47 48 // main task 49 SPortsCar.prototype.mainTasks = function () { 50 return "Driving SportsCar, loking Good, Beach Driving." ; 51 is }; 52 is 53 is }; 54 is 55 / * copy objects between * * / 56 is function CopyObject () { 57 is 58 the this .createCopyObject = function (parent, Child) { 59 for ( var prototype in parent) 60 { 61 if(!child[prototype]){ 62 child[prototype] = parent[prototype]; 63 } 64 }; 65 }; 66 67 }
Reproduced in: https: //www.cnblogs.com/FCWORLD/archive/2013/01/25/2877112.html