나는 codecademy.com의 코스를 따라 JavaScript bij를 배우려고 노력하고 있지만 'this'키워드를 이해하지 못하는 것 같습니다. 또한 사각형의 속성 너비와 높이를 변경해야합니다.Codecademy Javascript 'this'and solution
var rectangle = new Object();
rectangle.height = 3;
rectangle.width = 4;
// here is our method to set the height
rectangle.setHeight = function (newHeight) {
this.height = newHeight;
};
// help by finishing this method
rectangle.setWidth =
// here change the width to 8 and height to 6 using our new methods
현재 내가 가지고 :
var rectangle = new Object();
rectangle.height = 3;
rectangle.width = 4;
rectangle.setHeight = function (newHeight) {
this.height = newHeight;
};
rectangle.setWidth = function (newWidth) {
this.width = newWidth;
};
rectangle.setWidth = setWidth;
rectangle.setHeight = setHeight;
rectangle.setWidth(8);
rectangle.setHeight(6);
내가 무슨 일을 했는가 이것은 시작이다? 또한 오류 메시지는 setWidth를 정의하지 않았다는 것을 알려줍니다 ...
'this'도 설명하십시오.
@MrNirusu ??? 이 대답에 설명 된대로 잘못된 코드 줄을 제거하십시오. – Pointy
단순히 제거, 내 대답에 그것을 언급했다 –
@MrNirusu, 그것은 작동 했습니까? 그렇다면 내 대답을 수락하는 것을 고려하십시오. –