All JavaScript objects inherit properties and methods from a prototype.
The JavaScript prototype property also allows you to add new methods objects constructors:
ie : Date objects inherit from Date.prototype. Array objects inherit from Array.prototype. Person objects inherit from Person.prototype.
<script>
var Invoice = function(subtotal, taxRate) {
this.subtotal = subtotal;
this.taxRate = taxRate;
};
Invoice.prototype.getTaxAmount = function() {
return (subtotal * this.taxRate);
};
var myTax= new Invoice(10,5);
document.getElementById("demo").innerHTML =
"My tax amount is " + myTax.getTaxAmount ();
</script>
All JavaScript objects inherit properties and methods from a prototype.
The JavaScript prototype property also allows you to add new methods objects constructors:
ie : Date objects inherit from Date.prototype. Array objects inherit from Array.prototype. Person objects inherit from Person.prototype.
<script>
var Invoice = function(subtotal, taxRate) {
this.subtotal = subtotal;
this.taxRate = taxRate;
};
Invoice.prototype.getTaxAmount = function() {
return (subtotal * this.taxRate);
};
var myTax= new Invoice(10,5);
document.getElementById("demo").innerHTML =
"My tax amount is " + myTax.getTaxAmount ();
</script>
All JavaScript objects inherit properties and methods from a prototype.
The JavaScript prototype property also allows you to add new methods objects constructors:
ie : Date objects inherit from Date.prototype. Array objects inherit from Array.prototype. Person objects inherit from Person.prototype.
<script>
var Invoice = function(subtotal, taxRate) {
this.subtotal = subtotal;
this.taxRate = taxRate;
};
Invoice.prototype.getTaxAmount = function() {
return (subtotal * this.taxRate);
};
var myTax= new Invoice(10,5);
document.getElementById("demo").innerHTML =
"My tax amount is " + myTax.getTaxAmount ();
</script>
All JavaScript objects inherit properties and methods from a prototype.
The JavaScript prototype property also allows you to add new methods objects constructors:
ie : Date objects inherit from Date.prototype. Array objects inherit from Array.prototype. Person objects inherit from Person.prototype.
<script>
var Invoice = function(subtotal, taxRate) {
this.subtotal = subtotal;
this.taxRate = taxRate;
};
Invoice.prototype.getTaxAmount = function() {
return (subtotal * this.taxRate);
};
var myTax= new Invoice(10,5);
document.getElementById("demo").innerHTML =
"My tax amount is " + myTax.getTaxAmount ();
</script>