JavascriptObjects
HTML
Customer Name: <span id="CustomerName"></span>
<br />Invoice Amount: <span id="InvoiceAmount"></span>
<br />Sales Tax: <span id="SalesTax"></span>
<br />Invoice Total: <span id="InvoiceTotal"></span>
<br />
JavaScript
function invoice(parameter) {
//Properties
this.InvoiceAmount = 0;
this.SalesTaxPercent = .0675;
this.CustomerName = parameter;
this.SalesTax = computeSalesTax;
this.InvoiceTotal = computeTotal;
function computeSalesTax() {
var salesTax = this.InvoiceAmount * this.SalesTaxPercent;
return salesTax;
}
function computeTotal(multiplier) {
var multi = 1;
if (multiplier != null)
{
multi = multiplier;
}
var total = this.InvoiceAmount + this.SalesTax();
return multi*total;
}
}
function spencerIsAPartTimer(x){
return function JustKidding(y){
return "This guy, " + x + ", is a part timer! " + y;
}
}
$(document).ready(function () {
var invoice1 = new invoice("Greg Finzer");
invoice1.InvoiceAmount = 19.95;
$("#CustomerName").html(invoice1.CustomerName);
$("#InvoiceAmount").html(invoice1.InvoiceAmount);
$("#SalesTax").html(invoice1.SalesTax());
$("#InvoiceTotal").html(invoice1.InvoiceTotal(4));
var spencer = spencerIsAPartTimer("Spencer");
alert(spencer("Just kidding! Sucka!!!"));
var spencerString = spencer("Just kidding! Sucka!!!");
alert(spencerString + " -- !!!!!");
});