Subj : Private Data and Prototype Inheritance To : netscape.public.mozilla.jseng From : "Kevin Lindsey" Date : Fri Jan 09 2004 12:12 pm I've just started working with embedding SpiderMonkey into an app I'm writing. I've searched the archive and I haven't seen a clear solution to the problem I'm having. As an example, let's say that I implement a native class called Line which stores private data via JS_SetPrivate(). I'm able to modify my private data struct via Line's native getProperty and setProperty calls. Now, I want to create a "sub-class" of Line by doing the following: FancyLine.prototype = new Line(); function FancyLine() { Line.apply(this, arguments); } Each instance of Line and FancyLine need to have their own instance of private data. The JS above appears to work (attaches a new instance of private data to the FancyLine object) however, since I cannot mark FancyLine as having private data (done in JSClass structure), I am unable to retrieve that data in my Line's getProperty and setProperty functions when invoked from FancyLine. In other words, I can do this: var line = new Line(); line.x1 = 10.0; line.y1 = 10.0; but cannot do this: var fancyLine = new FancyLine(); fancyLine.x1 = 10.0; fancyLine.y1 = 10.0; even though the FancyLine example results in calls to Line's setProperty function with reference to the fancyLine object (which previously did have private data attached to it). So, what is the recommended way to allow subclassing of a native object while assuring that each descendant of that native class will have its own copy of private data. And I haven't gotten this far, but I assume some trick has to be used to release the private data when the descendant is finalized too. Thanks for any help with this, Kevin .