This example looks fine except for the first line, that colon should be an equal sign.
The problem, I'm guessing, has to do with how you're calling ShipProduct
. If you're doing it like this, everything should work:
var customer = new Customer();
customer.ShipProduct();
However if you detach the method and call it directly, it won't work. Such as:
var customer = new Customer();
var shipMethod = customer.ShipProduct;
shipMethod();
This is because JavaScript relies on the dot notation accessor to bind this
. I'm guessing that you're passing the method around, perhaps to an Ajax callback or something.
What you need to do in that case it wrap it in a function. Such as:
var customer = new Customer();
var shipMethod = function() {
customer.shipMethod();
};
... later, in some other context ...
shipMethod();