# Using the prototype function with Homemade Objects

**URL:** <https://forum.kirupa.com/t/using-the-prototype-function-with-homemade-objects/121611>\
**Category:** Uncategorized\
**Created:** [September 4, 2004, 4:17pm UTC](https://forum.kirupa.com/t/using-the-prototype-function-with-homemade-objects/121611 "2004-09-04T16:17:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pup\_100](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@Pup\_100](https://forum.kirupa.com/u/Pup_100)\
**Post date:** [September 4, 2004, 4:17pm UTC](https://forum.kirupa.com/t/using-the-prototype-function-with-homemade-objects/121611/1 "2004-09-04T16:17:06Z")

</div>

[font=Times New Roman]On doing a bit of work on “Homemade Objects” from examples provided in a reference book. I’m a little bit confused as to what the “prototype” function actually does.[/font]

[font=Times New Roman]According to the book if you have created two separate homemade objects (CD & BankAct) & then use the following code:[/font]

[font=Times New Roman][color=red]CD.prototype=new BankAct();[/color][/font]

[font=Times New Roman]CD will inherit ALL the “methods & properties” of BankAct, but if I run the following script, it would appear that none of the “Properties” have made it across into the “test” (New CD) object.[/font]

[font=Times New Roman][color=red]function BankAct(startingBalance,interestRate){[/color][/font]

[font=Times New Roman][color=red]this.balance=startingBalance;[/color][/font]

[font=Times New Roman][color=red]this.rate=interestRate;[/color][/font]

[font=Times New Roman][color=red]}[/color][/font]

[font=Times New Roman][color=red]function multiplyAndAdd(){[/color][/font]

[font=Times New Roman][color=red]this.balance+=(this.balance\*this.rate);[/color][/font]

[font=Times New Roman][color=red]}[/color][/font]

[font=Times New Roman][color=red]BankAct.prototype.compound=multiplyAndAdd;[/color][/font]

[font=Times New Roman][color=red]function CD(startingBalance,interestRate,lengthOfTermInDays){[/color][/font]

[font=Times New Roman][color=red]this.term=lengthOfTermInDays;[/color][/font]

[font=Times New Roman][color=red]var now=new Date();[/color][/font]

[font=Times New Roman][color=red]this.renewalDate=new Date();[/color][/font]

[font=Times New Roman][color=red]this.renewalDate.setDate(now.getDate()+this.term);[/color][/font]

[font=Times New Roman][color=red]this.longDate=this.renewalDate.toString();[/color][/font]

[font=Times New Roman][color=red]}[/color][/font]

[font=Times New Roman][color=red]CD.prototype=new BankAct();[/color][/font]

[font=Times New Roman][color=red]function extendDate(){[/color][/font]

[font=Times New Roman][color=red]this.renewalDate.setDate(this.renewalDate.getDate()+this.term);[/color][/font]

[font=Times New Roman][color=red]this.longDate=this.renewalDate.toString();[/color][/font]

[font=Times New Roman][color=red]}[/color][/font]

[font=Times New Roman][color=red]CD.prototype.renew=extendDate;[/color][/font]

[font=Times New Roman][color=red]test=new CD(100,.1,30);[/color][/font]

[font=Times New Roman][color=red]trace("init: " + test.balance + " "+test.longDate);[/color][/font]

[font=Times New Roman][color=red]test.compound();[/color][/font]

[font=Times New Roman][color=red]trace ("after compound: " + test.balance + " "+ test.longDate);[/color][/font]

[font=Times New Roman][color=red]test.renew();[/color][/font]

[font=Times New Roman][color=red]trace ("after renew: " + test.balance + " "+test.longDate);[/color][/font]

[font=Times New Roman]In other words unless I specify in it’s constructor that CD has got properties for “balance” & “rate” contrary to what the book says CD will not inherit them, as when I test the movie the “compound()”function shows 0 for the “After compound” amount?[/font]

[font=Times New Roman]So I suppose the bottom line is; does the prototype function transfer in both methods & properties?[/font]

[font=Times New Roman]Any help please. [/font]
