欢迎访问:常州市武进区嘉泽中心小学网站 !今天是:
栏目列表
您现在的位置是:首页>>教师>>计算机技术>>网站制作技术>>文章内容
javascript函数库:Integer.js
发布时间:2008-11-20   点击:   来源:本站原创   录入者:佚名
 

/**
* Integer for Java
* offen used for HashMap,HashSet, as same to Java!
*/
function testInteger(){
 alert("Integer test begin:");
 try{
  var i=new Integer(12);
  var j=new Integer(14);
  var k=new Integer(12);
  assert(i.intValue()==12);
  assert(i.toString()=="12");
  assert(i.hashCode()==12);
  assert(i.equals(k));
  assert(i.compareTo(j)<0);
 }
 catch(e){
  alert(e);
 }
 alert("Integer test end");
}
function Integer(num){
 private:
 this.value=parseInt(num);
 public:

 this.intValue=intValue;
 function intValue(){
  return this.value;
 }

 this.toString=toString;
 function toString(){
  return ""+this.value;
 }

 this.hashCode=hashCode;
 function hashCode(){
  return this.value;
 }

 this.equals=equals;
 function equals(obj){
  return this.intValue()==obj.intValue();
 }
 
 this.compareTo=compareTo;
 function compareTo(obj){
  var i=this.value-obj.value;
  return (i==0)?0:(i>0)?1:-1;
 }
}


附件:
    关闭窗口
    打印文档
    账号登录
    保持登录 忘记密码?
    账号与武进教师培训平台同步