站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Javascript 专题javascript函数库:Integer.js

javascript函数库:Integer.js

摘要: javascript函数库:Integer.js
<textarea readonly style="border:none;font-family:Courier New;line-height:150%;width:760px;overflow-y:visible">

/**
* 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;
}
}


</textarea>
↑返回目录
前一篇: javascript函数库:ArrayList.js
后一篇: javascript:HashMap.js