• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 21. Packaging Data and Functions... > Positioning Local Properties in the ...

Positioning Local Properties in the Inheritance Hierarchy

A constructor function can endow the instances that it creates with both local and shared properties. For instance, the following Bird constructor function gives a local makingNoise property and a shared move() method to each of its instances. Each instance needs its own copy of the makingNoise property to indicate whether it is making noise or not at a given moment.

function Bird ( )  { 
     this.makingNoise = false; // local “makingNoise” property 
} 
Bird.prototype.move = function () { }; // shared move() method 
myBird = new Bird(); 
myBird.hasOwnProperty(“makingNoise”); // true 


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint