$(".combinations .combination").each(function () {
if ($(this).data("id")) {
var i = {};
$(this).find(".metric").each(function () {
i[$(this).data("name")] = $(this).data("value")
});
var n = !0;
$.each(i, function (e) {
t.hasOwnProperty(e) && t[e] == i[e] || (n = !1)
}), (n || 0 == i.length) && (e.id = $(this).data("id"), e.url = $(this).data("url"), e.link = $(this).data("link"), e.name = $(this).data("name"), e.image = $(this).data("image"))}
}),
我是JavaScript的新手,并尝试通过阅读有趣的代码来学习。
请帮我理解上面的代码;什么是n =!0是什么意思?
这是什么以及如何运作?
t.hasOwnProperty(e) && t[e] == i[e] || (n = !1)
(n || 0 == i.length) && (e.id = $(this).data("id")
他们之间的逗号是什么意思?
答案 0 :(得分:0)
这是重新添加空白区域的缩小代码。它并不意味着被人类阅读,它意味着尽可能短。因此,有一些奇怪的事情,如:
!0 === true // 0 evals to false, "not false" = true
逗号只是添加新指令的一种方式。它们与JavaScript中的分号非常相似(尽管不完全相同)。例如你可以写x=5, y=10
hasOwnProperty
位有效:
if( !( t.hasOwnProperty( e ) && t[e] == i[e] ){
n = false;
}