2014-11-12 2 views
0

메신저는 자바 스크립트로 팩토리를 만들려고 시도하지만, 페이지 업로드시에는 을 상속하고 재생할 수 없습니다. 상속받은 클래스는 4 개였습니다. 하나의 슈퍼 clas,하지만 언제든지 나는 저녁 클래스에 기본값을 삽입 메신저하지만, 정의되지 않은 오류 obj를주는 코드를로드하려고 -Pc- 어떻게해야합니까?공장에서 상속을하려고하면 어떤 에러가 발생합니다.

function Pc(obj) { 
    this.type = obj.type || "enter Type"; 
    this.company = obj.company || "enter Company"; 
    this.warrenty = obj.warrenty || "enter Warranty"; 
    this.model = obj.model || "enter model"; 
    this.link = obj.link || "http://" + obj.link || "input link"; 
    this.price = obj.price || "Enter Price"; 
    this.picture = obj.picture || "input Pic"; 
    this.number = obj.number || "input number"; 
} 

function HardDrive(obj) { 
    this.rotationalSpeed = obj.rotationalSpeed || "7200RPM"; 
    this.buffersize = obj.buffersize || "64MB"; 
    this.capacity = obj.capacity || "1TB"; 
    this.Interface = obj.Interface || "'SATA 6 Gb/s"; 
} 
HardDrive.prototype = new Pc(); 

function Proccesor(obj) { 
    this.core = obj.core || 4; 
    this.cache = obj.cache || "4MB"; 
    this.speed = obj.speed; 
    this.inTheCart = false; 
} 
Proccesor.prototype = new Pc(); 

function Memory(obj) { 
    this.speed = obj.speed || "DDR3 1600"; 
    this.intrface = obj.intrface || "8GB"; 
    this.casLatency = obj.casLatency || '9'; 
    this.capacity = obj.Capacity || "8GB"; 
    this.inTheCart = false; 
} 
Memory.prototype = new Pc(); 

function MotherBoard(obj) { 
    this.socket = obj.socket || "1115"; 
    this.connection = obj.connection || "Alot"; 
} 
Memory.prototype = new Pc(); 

function ComputerFactory() { 
    this.newPart = function(obj) { 
     switch (obj.type.toLowerCase()) { 
      case "hardrive": 
       this.pcPart = HardDrive; 
       break; 
      case "proccesor": 
       this.pcPart = Proccesor; 
       break; 
      case "memory": 
       this.pcPart = Memory; 
       break; 
      case "motherboard": 
       this.pcPart = MotherBoard; 
       break; 
     } 
     return new this.pcPart(obj); 
    } 
} 
var x = new ComputerFactory(); 
var hd1 = ComputerFactory.newPart({ 
    type: "hardrive", 
    model: 'WD5000AAKX', 
    buffersize: '16 MB', 
    capacity: '500GB', 
    link: "www.google.co.il", 
    picture: 'WD500Gb.jpg', 
    price: 230, 
    number: 'hd1', 
}); 

답변

0

난 당신 때문에 다음 줄의 오류가 있다고 생각 -

HardDrive.prototype = new Pc(); 

당신의 PC 생성자 (방법을) 더 매개 변수의 경우를 처리하지 장착되어 있지 않습니다. 따라서 Pc 메서드에 아무 것도 전달하지 않으면 obj가 정의되지 않고 obj.type에 액세스 할 수 없습니다.

+0

감사하지만 작동하지 않지만 이전에 사용해 보았습니다. – Ilan

관련 문제