2014-10-31 2 views
0
function someClass(){ 
} 
someClass.prototype.CONST = 'Some Constant.'; 

console.log('with Obj : '+(new someClass).CONST); 
console.log('without Obj : '+someClass.CONST); 

첫 번째액세스 개체 인스턴스를 만들지 않고 프로토 타입 속성

내가 비슷한 찾고 있어요 개체 인스턴스를 생성하지 않고 CONST에 액세스 할 수있는 방법이 지금 정답, 정의되지 않은 두 번째 반환 을 제공합니다 자바 클래스

답변

4

엡의 정적 속성에 접근, 당신은 그것을 액세스 할 수 있습니다

console.log(someClass.prototype.CONST); 
0

당신은에 액세스 할 수 있습니다 객체의 프로토 타입 멤버를 통해 모든 원형 회원뿐만 아니라 변수 : 당신이 '호출 예'와 같은 다른 객체를 사용하여 하나의 객체에서 메소드를 호출해야하는 경우

// returns a value 
someObject.prototype.someMember 

// calls the function someFunct() 
someObject.prototype.someFunct() 

당신은 .call 또는 .apply

사용할 수 있습니다
// calls functMember using instanceObject as the instance 
someObject.prototype.functMember.call(instanceObject, arg1, arg2, ...); 

// calls functMember using isntanceObject as the instance, using an array as arguments 
someObject.prototype.functMember.call(instanceObject, [arg1, arg2, ...]); 
관련 문제