From: Leif W <war...@us...> - 2002-12-22 14:15:51
|
Hello, I'm working with some JavaScript to create a card game, and have come across the secondary inheritance bug (using IE 6.0.2800.1106 (SP1)), and was wondering if someone could explain the fix for the similar problem that was found in the dynapi. Ideally an explanation or example of a generalized solution or workaround for this problem would be most helpful (as opposed to a DynAPI-centric solution). The scenario in my code, I have a Pile object, and a Deck object, and two instances of the Deck object. I have a Deck.Populate method which fills the deck with cards. This method is called once from one instance, but both decks become populated. The Decks have a Name property which seems to be ok, but the methods apparently aren't inherited properly. My card game is in prototyping now, so that I can get the core game working and modularized (for different card games), but I plan to make a DynAPI version, along with Java Applet, Flash, and PHP versions (from text-only standalone up to full GUI and client/server multiplayer). This isn't part of any corporate venture, it's solely for the purpose of self-education and exercise. Any help would be appreciated. Sincerly, Leif W warp-9.9 |
From: Leif W <war...@us...> - 2002-12-22 15:23:34
|
Below is a simplified version of the relevent bits of my code which demonstrates the problem more clearly. Here's a summarization of the code: * Pile and Deck object definitions. Deck inherits from Pile, and extends with Populate method. * onLoad, a function initializes some variables whose values are form elements. * click the init button, initialize two decks (deck1 and deck2). * click the populate button, populate deck1 only. * click the display button, shows deck1 and deck2 have been populated. Things to note: * the Name property of Pile is correctly holding two different values for each instance of Deck. * the Cards array property is incorrectly holding a reference to the same array. <HTML> <HEAD> <TITLE>Uno Card Game Prototype</TITLE> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <SCRIPT LANGUAGE="JavaScript"> <!-- Pile = function ( ) { this.Name = ''; this.Cards = new Array( ); this.displayObj = new Object( ); }; Pile.prototype.init = function ( name , displayObj ) { this.setName( name ); this.setDisplayObj( displayObj ); }; Pile.prototype.setName = function ( name ) { this.Name = name; }; Pile.prototype.getName = function ( ) { return( this.Name ); }; Pile.prototype.setDisplayObj = function ( displayObj ) { this.displayObj = displayObj; }; Pile.prototype.getDisplayObj = function ( ) { return( this.displayObj ); }; Pile.prototype.getNumCards = function ( ) { return( this.Cards.length ); }; Pile.prototype.Display = function ( ) { var numCards = this.getNumCards( ); var msg = 'Deck: ' + this.getName( ) + '(' + numCards + ' cards)\n'; for ( var i = 0 ; i < numCards ; i++ ) { msg += i + ': ' + this.Cards[i] + '\n'; } this.getDisplayObj( ).value = msg; }; Deck = new Function( ); Deck.prototype = new Pile( ); Deck.prototype.Populate = function ( ) { var colors = new Array( 'red' , 'orn' , 'ylw' , 'grn' , 'blu' , 'vlt' ); for ( var i = 0 ; i < colors.length ; i++ ) { this.Cards[i] = colors[i]; } }; var deck1 = new Object( ); var deck2 = new Object( ); var deck1LogObj = new Object( ); var deck2LogObj = new Object( ); var activityLogObj = new Object( ); var initFlag = false; function test_global_init ( ) { deck1 = new Object( ); deck2 = new Object( ); deck1LogObj = document.forms[ 'table' ].deck1_log; deck2LogObj = document.forms[ 'table' ].deck2_log; activityLogObj = document.forms[ 'table' ].activity_log; }; function test_deck_init ( ) { if ( initFlag == false ) { deck1 = new Deck( ); deck2 = new Deck( ); deck1.init( 'Deck One' , deck1LogObj ); deck2.init( 'Deck Two' , deck2LogObj ); activityLogObj.value = 'deck1 (' + deck1.getName( ) + ') and ' + 'deck2 (' + deck2.getName( ) + ') initialized.\n'; initFlag = true; } else { activityLogObj.value += 'Decks already initialized.\n'; } }; function test_deck_populate ( ) { deck1.Populate( ); activityLogObj.value += deck1.getName( ) + ' populated.\n'; }; function test_deck_display ( ) { deck1.Display( ); deck2.Display( ); activityLogObj.value += 'Decks displayed.\n'; }; function test_deck_clear ( ) { deck1LogObj.value = ''; deck2LogObj.value = ''; activityLogObj.value = ''; }; //--> </SCRIPT> </HEAD> <BODY BGCOLOR="#000000" TEXT="#FFFFFF" LINK="#00FF00" ALINK="#FF0000" VLINK="#990000" TOPMARGIN="5" BOTTOMMARGIN="5" LEFTMARGIN="5" RIGHTMARGIN="5" MARGINHEIGHT="5" MARGINWIDTH="5" onLoad="test_global_init( );"> <FORM NAME="table" METHOD="post" ACTION="" onSubmit="return( false );"> <TABLE BGCOLOR="#FF00FF" BORDER="0" CELLPADDING="0" CELLSPACING="2"> <TR> <TD> <TABLE BGCOLOR="#000000" BORDER="0" CELLPADDING="0" CELLSPACING="5"> <TR> <TD><FONT SIZE="2" FACE="Verdana, Arial"> <INPUT TYPE="button" NAME="deck_init_test" VALUE="init" onClick="test_deck_init( );"> <INPUT TYPE="button" NAME="deck_populate_test" VALUE="populate" onClick="test_deck_populate( );"> <INPUT TYPE="button" NAME="deck_display_test" VALUE="display" onClick="test_deck_display( );"> <INPUT TYPE="button" NAME="deck_clear_test" VALUE="clear" onClick="test_deck_clear( );"> <BR> <TEXTAREA NAME="deck1_log" COLS="20" ROWS="10" TYPE="virtual"></TEXTAREA> <TEXTAREA NAME="deck2_log" COLS="20" ROWS="10" TYPE="virtual"></TEXTAREA> <BR> <TEXTAREA NAME="activity_log" COLS="40" ROWS="10" TYPE="virtual"></TEXTAREA> </FONT></TD> </TR> </TABLE> </TD> </TR> </TABLE> </FORM> </BODY> </HTML> ----- Original Message ----- From: "Leif W" <war...@us...> To: <dyn...@li...> Sent: Sunday, December 22, 2002 9:20 AM Subject: [Dynapi-Chat] JavaScript secondary inheritance bug. > Hello, > > I'm working with some JavaScript to create a card game, and have come across > the secondary inheritance bug (using IE 6.0.2800.1106 (SP1)), and was > wondering if > someone could explain the fix for the similar problem that was found in the > dynapi. > Ideally an explanation or example of a generalized solution or workaround > for this > problem would be most helpful (as opposed to a DynAPI-centric solution). > > The scenario in my code, I have a Pile object, and a Deck object, and two > instances of the Deck object. I have a Deck.Populate method which fills the > deck with cards. This method is called once from one instance, but both > decks become populated. The Decks have a Name property which seems to be > ok, > but the methods apparently aren't inherited properly. > > My card game is in prototyping now, so that I can get the core game working > and modularized (for different card games), but I plan to make a DynAPI > version, along with Java Applet, Flash, and PHP versions (from text-only > standalone up to full GUI and client/server multiplayer). This isn't part > of any corporate venture, it's solely for the purpose of self-education and > exercise. > > Any help would be appreciated. > > Sincerly, > > Leif W > warp-9.9 > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Dynapi-Chat mailing list > Dyn...@li... > https://lists.sourceforge.net/lists/listinfo/dynapi-chat > |