java类风格的js

来源:互联网 发布:假ip攻击软件 编辑:程序博客网 时间:2024/04/30 13:11

 

 

<SCRIPT LANGUAGE="JavaScript"> 
<!-- 
myClass
=new function ()//区别之处
...
        
var isLock=false
        
function check(str)
        
...{
                
if(isLock) 
                
...
                        alert(
'lock!'+"  Go this way in "+str); 
                        
return false
                }
 
                
return true
        }
 
        
function reset()
        
...
                isLock
=true
        }
 
        
this.property1='property1'
        
this.method=function()
        
...
                alert(
'mothod'); 
        }
 
        
this.method1=function(str)
        
...
                
if(!check(str))return
                isLock
=true
        }
 
}
 
alert(myClass.property1); 
myClass.method(); 
myClass.method1(
"first"); 
myClass.method1(
"second"); 
//--> 
</SCRIPT> 

 

 

<SCRIPT LANGUAGE="JavaScript"> 

function myClass()//
...
        
var isLock=false
        
function check(str)
        
...{
            
if(isLock) 
            
...
                alert(
'lock!'+"  Go this way in "+str); 
                
return false
            }
 
            
return true
        }
 
        
function reset()
        
...
            isLock
=true
        }
 
        
this.property1='property1'
        
this.method=function()
        
...
            alert(
'mothod'); 
        }
 
        
this.method1=function(str)
        
...
            
if(!check(str))return
            isLock
=true
        }
 
}
 

var obj=new myClass();
alert(obj.property1)
obj.method();
obj.method1(
"first");
obj.method1(
"second");


</SCRIPT>