이 Possible duplicate이 나에게 도움이되지 않았다. 나는 비슷한 질문 때문에 인터뷰에서 실패했다.객체를 모듈 패턴과 결합 할 때 내가 뭘 잘못하고 있니?
module pattern
과 inheritance
을 사용하여 관리자의 선배이자 할아버지 인 사람 Object
을 만드는 것이 좋습니다.
내 코드처럼 보이는 관리자 -> Teacher-> 사람처럼 뭔가 (My Plunk) :
var person = new APP.Person('Aria Stark','22323');
이 오류는 다음과 같습니다
(function(undef)
{
/**Waiting till document is ready before applying next functions*/
$(document).ready(function(){
var person = new APP.Person('Aria Stark','223232');
document.write(person.getDetails());
})();
var APP = {};
APP.Person =(function() {
function Person(name, ID) {
this.name = name;
this.ID = ID;
}
Person.prototype.getDetails = function() {
return " name: " + this.name + " ID: " + this.ID;
};
return Person;
});
APP.Teacher =(function() {
function Teacher(name, ID, salary, hatColor) {
APP.Person.call(this, name, ID);
this.salary = salary;
this.hatColor = hatColor;
}
Teacher.prototype = new APP.Person();
Teacher.prototype.getDetails = function() {
return APP.Person.call(this) + " Salary: " + this.salary + " Hat: " + this.hatColor;
};
return Teacher;
});
APP.Manager =(function() {
function Manager(name, ID, salary, hatColor, car) {
APP.Teacher.call(this, name, ID, salary, hatColor);
this.car = car;
}
Manager.prototype = new APP.Teacher();
Manager.prototype.getDetails = function() {
return APP.Teacher.call(this) + " Car: " + this.car;
};
return Manager;
});
})();
나는 첫 번째 줄에 오류가 : Uncaught TypeError: object is not a function
누군가 나를 도와 줄 수 있습니까? 또한이 코드의 다른 개선 사항에 대해서도 열려 있습니다.
감사합니다,하지만이 답변이 새로운 문제로 연결 : http://plnkr.co/edit/fyg4JDBQp9DSzvI6pvOx?p=preview, 교사용 개체를 만들려고 할 때 – Canttouchit
@Canttouchit 내가 살펴 보겠습니다. 한편'document.write'는'console.log'라는 것을 잊어 버리십시오. 매우 유용합니다. – kapa
네, 깜빡 :'return APP.Person.prototype.getDetails.call (this)' – Canttouchit