private static and multi-inherit

C

csf178

/*author:[email protected]*/
function Class(Initalizer,SuperClasses)
{
if(!SuperClasses)SuperClasses=[];
var ret=function(){
for(var i=0;i<SuperClasses.length;i++)
{
SuperClasses.call(this);
}

var $private={};
var $public=this;
var $static=ret;


with($static){
with($private){
with($public){
eval("("+Initalizer
+").apply(this,arguments)");
}
}
}
return this;
}


ret.prototype=Initalizer.prototype;


for(var p in
Initalizer.prototype)ret.prototype[p]=Initalizer.prototype[p];
for(var p in Initalizer)ret[p]=Initalizer[p];
for(var i=0;i<SuperClasses.length;i++)
{
for(var p in SuperClasses.prototype)
{
ret.prototype[p]=SuperClasses.prototype[p]
}
}
return ret;



}


/*
function alert(s)
{
WScript.echo(s);

}


*/

/***********************************************
Example$B!'(Bpublic static private
************************************************/


var test1=new Class(function(){


//v1 is public
$public.v1=1;


//v2 is private
$private.v2=2;


//define public variable with this
this.vv1=2;


//public function member
$public.show=function(){
//visit public and private variable
alert(v1);
alert(v2);
}
$public.set_static=function(v){
$static.v3=v;
}



});


var obj=new test1();

//visit public variable
alert(obj.v1);
alert(obj.vv1);


//try to visit private variable
alert(obj.v2);


//call public member function
obj.show();


//set static variable
obj.set_static(10);
//visit static variable from class
alert(test1.v3);


/***********************************************
Example:multi-inherit
************************************************/
var parent=function(){this.v4=6};
parent.prototype.v5=1000;


var test2=new Class(function(){
$public.show2=function(){
alert(this.v1);
alert(v4);
alert(v5);
}



},[test1,parent]);


var obj=new test2();
obj.show2();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top