JavaScript의 깊이에 모험을하고 있으며 머리를 감을 수없는 작은 문제가 있습니다.오브젝트 내부의 JavaScript 새 오브젝트
프로그래밍에 대해 알고있는 모든 것은 스스로 가르쳐지며,이 문제는 내가 들어 본 적이없는 용어를 가지고있을 수 있으므로 무엇이 호출 될지 모른다.
내가 겪고있는 문제에 대해 설명하겠습니다.
저는 2 차원 및 3 차원 그래픽을 표시하기위한 HTML5 캔버스 용 프레임 워크를 작성했습니다.
예상대로, 저는 요소 클래스를 설계했습니다.이 요소들은 내가 조립 한 벡터 클래스에서 만들어진 캔버스에 위치를가집니다.
나는이 "텍스트"개체를 만들 경우, 다음 자신의 위치 개체 내에서 함수를 호출되는 데 문제는 "텍스트"개체의 모든 위치는이 값으로 변경:
var usernameLabel = new C.Text('Username:');
usernameLabel.position.set(30,30)
var username = new C.Text('Hello World');
username.position.set(0,70)
console.log(usernameLabel.position.x) // 0 when it should be 30
나는 내가 놓친 것이 있다고 확신한다. 나는 무엇을 알아낼 수 없다.
C.Text.prototype = new C.Element();
C.Element.position = new JC.Vector();
모든 도움을 주시면 감사하겠습니다. 보내는 사람
C.Rectangle = function(width, height)
{
this.style.setSize(width,height);
}
C.Rectangle.prototype = new C.Element();
C.Rectangle.prototype.constructor = new C.Rectangle();
var usernameLabel = new C.Text('Username:');
usernameLabel.position.set(30,30) // 0,70?
var username = new C.Text('');
username.position.set(0,70) // 0,70
var rect = new C.Rectangle(20,0);
rect.position.set(30,80) // 90,80?
var rect2 = new C.Rectangle(20,0);
rect2.position.set(90,80) // 90,80
@ user4030 jsBin 또는 jsFiddle에 게시하여 살펴볼 수 있습니다. 여기에서 읽기가 어려울 것입니다. – Ktash
설명에 전체 클래스를 추가했습니다. – user4030
다음 텍스트 클래스를 추가하겠습니다. – user4030