Basically all we've done is told the Table() Constructor Function that any object extended from it has access to the methods by adding the following syntax to the body of the Table() function: "this.methodName = functionName".
function Table(border,color) {Then we took all the document.write() statements from the previous example and put them in a function body referencing the name given to it in the Table() function.
this.tableOpen = "<table border=" + border + ">"
this.trOpen = "<tr>"
this.tdOpen = "<td bgcolor=" + color + ">"
this.text = "<b>This border's size is " + border + " and the background is " + color + ".</b>"
this.tdClose = "</td>"
this.trClose = "</tr>"
this.tableClose = "</table>"
this.showTable1 = showTable1 //this.methodName = functionName, can be the same name
}
function showTable1() {Now if you so desired, you could write 1,000 tables to the page simply by invoking the method on your new object 1,000 times. Sure beats coding each document.write() statement 1,000 times!
document.write(this.tableOpen)
document.write(this.trOpen)
document.write(this.tdOpen)
document.write("Here is some Text")
document.write(this.tdClose)
document.write(this.trClose)
document.write(this.tableClose)
}
TableOne = new Table("10","orange") //extend objectView the Source
TableOne.showTable1() // invoke method on object