Here is a simplified example of the problem I am having.
function Part(price, qty) {
this.price = price;
this.qty = qty;
this.value = function() {
return this.price * this.qty
}
}
var fancyPart = new Part(2, 3);
console.log(fancyPart.value)
I would like for this to print 6
to the console, instead it is printing:
function () {
return this.price * this.qty
}
Why is this happening?
I am trying to use this to create an "object" and was reading about the various methods over at this question: Which way is best for creating an object in javascript? is "var" necessary before variable of object?