Search the web
Sign In
New User? Sign Up
jsolait
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Version 2.0: Yes!!!!   Message List  
Reply | Forward Message #280 of 411 |
Version 2.0 is great! Now we can get subclasses to retain their
private variable correctly. You can run the html below to see what I
mean. Change the jsolait.js path if needed.



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML
4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-
1">
<title>Test</title>

<script type='text/javascript' src='./jsolait/jsolait.js'></script>
</head>
<body>
<script type='text/javascript'>

Super = Class(function(publ, priv){
// PRIVATE PROPERTIES
var sTest = "Super";

// CONSTRUCTOR
publ.__init__ = function (){
this[priv] = {};
this[priv].test = 'In Super';

return this;
};

// ACCESSOR FUNCTIONS
// these next methods can be inherited by subclasses
which will
// retain the value for this[priv].test in each subclass
instance properly
// but will not retain var sTest correctly!
publ.setVarTest = function(sNewTest){
sTest = sNewTest;
};
publ.setPrivTest = function(sNewTest){
this[priv].test = sNewTest;
};
publ.getVarTest = function(){
return sTest;
};
publ.getPrivTest = function(){
return this[priv].test;
};

}) // end of class

Sub = Class(Super, function(publ, priv, supr){
// PRIVATE PROPERTIES
var sTest = "Super";

// CONSTRUCTOR
publ.__init__ = function(){
supr.__init__.call(this);
this[priv] = {};
this[priv].test = 'In Sub';
return this;
};

// ACCESSOR FUNCTIONS
// these are inherited from Super

}) // end of class

var oSub_A = new Sub();
var oSub_B = new Sub();
var oSub_C = new Sub();

oSub_A.setPrivTest("A");
oSub_B.setPrivTest("B");
oSub_C.setPrivTest("C");

oSub_A.setVarTest("A");
oSub_B.setVarTest("B");
oSub_C.setVarTest("C");

alert("Test Results:"+
"\ngetPrivTest():\n"+
oSub_A.getPrivTest()+" "+oSub_B.getPrivTest()+" "+oSub_C.getPrivTest
()+
"\ngetPrivTest():\n"+
oSub_A.getVarTest()+" "+oSub_B.getVarTest()+" "+oSub_C.getVarTest()
);


</script>
</body>
</html>



The alert will display "A B C" for getPrivTest() and
"C C C" for getVarTest()! This has been a problem
in version 1 but not anymore!

Thanks again,
Dave








Fri Sep 29, 2006 3:38 am

orchidsonline
Offline Offline
Send Email Send Email

Forward
Message #280 of 411 |
Expand Messages Author Sort by Date

Version 2.0 is great! Now we can get subclasses to retain their private variable correctly. You can run the html below to see what I mean. Change the...
Richard D. Spencer
orchidsonline
Offline Send Email
Sep 29, 2006
3:47 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help