我理解的其中一些代码,但" {}"这是什么意思...??
var Accordion = function(el, multiple) {
this.el = el || {};
this.multiple = multiple || false;
// Variables
var link = this.el.find('.link');
// Eventos
link.on('click', {el: this.el, multiple: this.multiple},this.dropdown)
}
答案 0 :(得分:8)
{}
表示一个空的Javascript对象(与new Object()
相同),上面没有自定义属性或方法。
所以,这句话:
// if el contains a value, do this.el = el, otherwise init this.el to an empty object
this.el = el || {};
在逻辑上等同于:
if (el) {
this.el = el; // initialize from function argument
} else {
this.el = {}; // initialize to an empty object
}
或者用文字 “如果el
包含非空/非空的真值,则将其分配给this.el
,否则初始化this.el
空对象“ 。
这是一个快捷符号,用于使变量初始化,列表中的第一个变量是真实的,因为Javascript的||
运算符会求值,直到找到第一个真值操作数,然后停止评估并将该操作数作为值。
答案 1 :(得分:2)
它表示没有方法或属性的JavaScript对象。
答案 2 :(得分:1)
// if "this.el" didn't exist, assign it to an empty object {}
this.el = this.el || {};
console.log(el);
在此处试试:http://goo.gl/CkRlNB