/我是按书上打出来的 为什么显示range is not defined,不太明白,我也没得range没定义,但不知道哪里错了/
function Range(from,to){
this.from=from;
this.to=to;
}
Range.prototype={
includes:function(x){
return this.from<=x&&x<=this.to;
},
foreach:function(f){
for(var x=Math.ceil(this.form);x<=this.to;x++)f(x);
},
toString:function(){
return "("+this.form+"..."+this.to+")";
}
};
var r=range(1,3); //
r.includes(2); //
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
大哥是不是少了个new,而且是大写R
var r = new Range(1,3);
肯定是R没大写了...
JS的函数名大小写敏感,PHP的不敏感,有区别哦
请下次注意好编辑描述和代码
这是你要的内容,对比一下区别