저는 PortraitOrder()라는 클래스의 생성자가 들어있는 .js 파일을 가지고 있습니다. CalculateCost()라는 메서드가 있습니다. 어떤 이유로 CalculateCost() 메서드를 나중에 호출해도 아무 일도 일어나지 않습니다. 여기 자바 스크립트 메서드 CalculateCost() 나를 위해 어떤 값도 반환하지 않습니다.
- 는 여기
function PortraitOrder(portrait, copies, size, buyer){ this.portrait = portrait; this.copies = copies; this.size = size; this.buyer = buyer; function CalculateCost(){ this.size = size; this.copies = copies; var price; if(size == "wallet"){ price = 10; } else if(size == "8x10"){ price = 10; } else if(size == "4x6"){ price = 10; } else if(size == "11x14"){ price = 30; } else{ price = 10; } var cost = price * copies; return cost; } }
내가 방법을 호출하는 방법입니다 PortraitOrder()와 CalculateCost()이다
var cost = CalculateCost().toFixed(2); document.write("Price of Order: " + cost + "<br/>");
불행하게도,이 과제의 일부입니다. 나는 그것을 portraitorder() 안에 넣어야합니다. – Historiun
아, 회원 기능으로 설정하고 싶습니다. 당신은 질문에서 (또는 적어도 당신의 코드에서 분명하지 않다는 것을) 명시하지 않았다. PortraitOrder.prototype.calculateCost = function() {}을 수행 할 수 있습니다. –
오케이. 그렇다면 내 변수 선언이 맞습니까? – Historiun