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