Javascript函数总是返回true
Javascript function always returns true?
我有这个函数它是一个对象的属性,
Layer.prototype.mouseInBounds = function() {
// Return value
var ret = true;
// Layer mouse co-ordinates are not valid
if (this.mouse.x < 0 || this.mouse.y < 0 || this.mouse.x >= this.width || this.mouse.y >= this.height) {
// Set layer mouse co-ordinates to false
this.mouse.x = false;
this.mouse.y = false;
// Set return value
ret = false;
}
return ret;
};
但是当我在另一个具有图层属性的对象中这样调用它时,
this.layer.mouseInBounds() // true
无论mouseInBounds
函数中ret
的值是多少?
编辑
为了更好地理解我的问题mouse
是层的属性,当添加
console.log(ret);
在返回语句之前,我确实得到了true
或false
,
总是返回true
,因为:
-
this.mouse.x < 0
总是false
, -
this.mouse.y < 0
总是false
, -
this.mouse.x >= this.width
总是false
, -
this.mouse.y >= this.height
总是false
我不知道mouse.x
和mouse.y
具体代表什么,但如果它们是从窗口左上角测量的x/y鼠标坐标,那么我不知道它们怎么会小于0
。
相关文章:
- 对于loop.if-仅在经过所有间隔后返回true
- 如果函数返回True,则显示Javascript按钮
- Javascript If else 只返回 TRUE 或只返回 FALSE
- 过滤器返回true或false
- 我对“;返回true"嵌套函数内部;t工作
- 如何在成功输入时使“返回TRUE”
- 检查一个元素是否有一个类与另一个类总是返回true
- JavaScript函数未返回true
- 如果URL中有任何字符串变体匹配,则返回true
- 如何使以下函数返回true或false
- 使用“in”关键字检查 0 始终返回 true
- hasOwnProperty 在对照父对象属性进行检查时返回 true
- 为什么 isNaN 总是返回 true
- _.数组中的每个查找值都返回 true 或 false.使用下划线 JS
- 错误地返回true
- 为什么asp:LinkButton服务器端事件没有'当clientClick返回true时,t激发
- 阻止表单提交 javascript 为什么有一个明显的错误语句返回 true
- Node js命令器args返回true而不是值
- 如何将html表单与php链接,以便在例如单击按钮时返回true
- 从OnClientClick调用函数时,在JavaScript中返回true