我尝试了以下代码:
$(document).ready(function(){
setInterval(function() {
$('#result').text(collision_(workerTasks()));
console.log(tasks);
}, 200);
});
function workerTasks() {
var tasks = '';
$('#worker1 [id^=task]').each(function(i){
var comma = $('#worker1 [id^=task]').length == i ? '' : ',';
tasks += $('#' + $(this).attr('id')) + comma;
});
return tasks;
}
function collision_() {
if (arguments.length > 1) {
for (var x = 0; x < arguments.length; x++) {
for (var y = 1; y < arguments.length; y++) {
if (x == y) {
continue;
}
if (collision(arguments[x], arguments[y])) {
return true;
}
}
}
return false;
}
}
function collision($div1, $div2) {
var x1 = $div1.offset().left;
var y1 = $div1.offset().top;
var h1 = $div1.outerHeight(true);
var w1 = $div1.outerWidth(false);
var b1 = y1 + h1;
var r1 = x1 + w1;
var x2 = $div2.offset().left;
var y2 = $div2.offset().top;
var h2 = $div2.outerHeight(true);
var w2 = $div2.outerWidth(false);
var b2 = y2 + h2;
var r2 = x2 + w2;
if (b1 < y2 || y1 > b2 || r1 < x2 || x1> r2) return false;
return true;
}
它可以编译(在scala版本2.12.2),但在运行时抛出异常:
class C(val g: Int => Int)
object C {
object A extends {
var f: Int => Int = x => x
} with C(x => f(x) + 1)
def main(args: Array[String]): Unit = {
println(A.g(3))
}
}
为什么会这样?
答案 0 :(得分:1)