How to call a function by passing an object name?


In the code of this lesson, I have made a function to call the discount from an object. but I cannot let the function recognize the object:

function StaffMember(name,discountPercent){ = name;
this.discountPercent = discountPercent;

var me = new StaffMember("S", 20);

var cashRegister = {
lastTransactionAmount: 0,
add: function(itemCost){ += (itemCost || 0);
this.lastTransactionAmount = itemCost;
scan: function(item,quantity){
switch (item){
case "eggs": this.add(0.98 * quantity); break;
case "milk": this.add(1.23 * quantity); break;
case "magazine": this.add(4.99 * quantity); break;
case "chocolate": this.add(0.45 * quantity); break;
return true;
voidLastTransaction : function(){ -= this.lastTransactionAmount;
this.lastTransactionAmount = 0;
// Create a new method applyStaffDiscount here
applyStaffDiscount: function(employee) { -= * (employee.disountPercent / 100);



In the last code, I used both me as it is or "me" with quotes, it still cannot work well. Could anyone help me to figure out what I can do with this problem please? Thank you!



Have a close look at



Figured it! Thanks a lot!!