1
... status()
방법은 존재하지 않고 내가 그렇게 같은 return { ... }
를 제거한다면 나는, 그러나 :(를 호출 할 수 없습니다 ...개체의 프로토 타입 체인에서 호출 할 수있는 메서드는 언제 있습니까?
var org = {};
org.Organization = function() {
var app = null;
function setupApplication() {};
return {
init : function() {
console.log("init");
}
}
};
org.Organization.prototype = {
status : function() {
console.log("status");
}
};
var myOrg = new org.Organization();
myOrg.init(); // outputs "init"
myOrg.status(); // TypeError: Object #<Object> has no method 'status'
...이 코드를 고려
var org = {};
org.Organization = function() {
var app = null;
function setupApplication() {};
};
org.Organization.prototype = {
status : function() {
console.log("status");
}
};
var myOrg = new org.Organization();
myOrg.init(); // TypeError: Object #<Object> has no method 'init
myOrg.status(); // outputs "status"
가 ... 다음
status()
방법이 존재하고 내가 아무런 문제없이 호출 할 수 있습니다. 왜 이런 일이? 왜 프로토 타입 체인에 방법은 원래의 오브젝트가
return { ... }
이없는 경우에만?라는
return { ... }
덮어 쓰기를합니까 할 수 있습니다 또는 프로토 타입 cha의 메소드보다 우선 함 에서?
+1 ohhhhh ... 많은 의미가 있습니다! 고마워요 :) – Hristo
다행히 도왔습니다! – deviousdodo