는 자바 스크립트 코드를 고려하십시오 :배열을 자바 스크립트에서 객체의 속성으로 만드는 방법은 무엇입니까?
function Selector() {
this.Status = "";
this.Groups = new Array();
this.Errors = new Array();
}
내가 선택기 클래스 그룹 속성에 대한 방법을 추가 인스턴스를 위해 그것을 사용하려고합니다. 내가 어떻게 할 수 있니?
오류 : selector.Groups.myFunction 함수
하지이 코드 쓰기 양해하여 주시기 바랍니다 :
function Selector() {
this.Status = "";
this.Groups = [];
this.Groups.myFunction = function(){alert(this.length);
};
this.Errors = [];
}
var selector = new Selector();
selector.Groups = [1,2,3];
selector.Groups.myFunction();
을하지만 난이 그룹의 속성을 설정할 때 내가 방법을 호출하는 오류
프로토 타입 객체를 사용하는 방법을 찾는 것을 선호합니다.
감사합니다.
'this.Groups.myFunction = 기능() {};. ' –