The code has the following three objects.
Activity Payment Refund
Activity defines the function that will be used to generate the output (payments, refunds, and so on). Payment and Refund share the same prototype, so all you need to do is declare them in the code.
Next, the code defines three objects that will be used as the parameters to the Activity function. Amount is the input parameter for Payment and Receiver for Refund.
Finally, the Activity function is defined. This function will take three object parameters: Amount, Receiver, and an optional sender parameter.
Each object in the code has a corresponding method. Amount is assigned a value using the setAmount method, Receiver is set to the receiver parameter, and sender is set to null if not provided.
function Activity(amount) {
this.amount = amount;
}
Activity.prototype.setAmount = function (value) {
if (value <= 0) {
return false;
} else {
this.amount = value;
return true;
}
};
Activity.prototype.getAmount = function () {
return this.amount;
};
function Payment(amount, receiver) {
this.amount = amount;
this.receiver = receiver;
}
Payment.prototype = Object.create(Activity.prototype);
Payment.prototype.setReceiver = function (receiver) {
this.receiver = receiver;
};
Payment.prototype.getReceiver = function () {
return this.receiver;
};
function Refund(amount, sender) {
this.amount = amount;
this.sender = sender;
}
Refund.prototype = Object.create(Activity.prototype);
Refund.prototype.setSender = function (sender) {
this.sender = sender;
};
Refund.prototype.getSender = function () {
return this.sender;
};