spacer
Yehuda Shiran February 24, 2001
Keeping the Prototyping Information
Tips: February 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management
JavaScript stores the prototyping relationship in an internal property of the object, __proto__ (two underscore characters at the front and two at the end.) Let's take an example:

<SCRIPT LANGUAGE="JavaScript">
function Shape() {
  this.borderWidth = 5;
}

function Square() {
  this.edge = 12;
}

Square.prototype = new Shape;

myPicture = new Square;

alert(myPicture.__proto__);
alert(myPicture.borderWidth);
</SCRIPT>

The object myPicture has an internal property, __proto__, which is set to Shape when the statement:

Square.prototype = new Shape;
is executed. The value of __proto__ instructs JavaScript where to look for properties, when local definitions are not available. In the example above, the property borderWidth is not defined within the object Square. The browser looks for the value of __proto__, which is Shape, and then fetches the value of its borderWidth property. Being an internal property, most browsers will return undefined when asked to alert __proto__. Netscape 6, though, returns <object object>.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags