에서 함수를 사용하는 방법 다음 코드 나던 작업 :자바 스크립트 : 내가 생성자
function CClass() {
myFunc(); //says it doesnt know about myFunc
}
CClass.prototype = {
myFunc: function() {}
};
감사합니다!
에서 함수를 사용하는 방법 다음 코드 나던 작업 :자바 스크립트 : 내가 생성자
function CClass() {
myFunc(); //says it doesnt know about myFunc
}
CClass.prototype = {
myFunc: function() {}
};
감사합니다!
CClass.prototype.myFunc = function(){
alert("myFunc")
};
function CClass() {
this.myFunc();
}
c = new CClass()
myFunc
는 전역 범위에 있지 않습니다.
당신은이 작업을 수행하려고
function CClass() {
this.myFunc();
}
사용해야합니까?
function CClass() {
this.myFunc()
}
CClass.prototype = {
myFunc: function() {
alert('hello from prototype');
}
};
var cc = new CClass(); // hello from prototype
나는이 스 니펫이 기대하는 바를 실제로 이해하지 못합니다. 이걸 좀 더 설명해 주시겠습니까? – Chris
정확히 달성하려는 것은 무엇입니까? – fcalderan