<script>
(function() {
$('html').addClass('js');
var contactForm = {
container: $('#contact'), <-- THIS COMMA
init: function() {
$('<button></button>', {
text: 'Contact Me'
})
.insertAfter('article:first')
.on('click', this.show);
}, <---------------------------------- AND THIS COMMA
show: function() {
contactForm.container.show();
}
};
contactForm.init();
})();
</script>
在上面的脚本中,我注意到:
容器:$('#contact'),
这是声明变量的一种方式吗?执行以下操作会破坏脚本:
var container = $('#contact');
还有,init函数后面的逗号和容器变量(如果是变量的话)是什么意思?
最佳答案
这样声明一个对象:
var contactForm = {
// properties:
property1 : value,
property2 : value,
property3 : value,
// methods:
method1 : function() {
// ...
},
method2 : function() {
// ...
}
};
您可以在 MDN 中找到有关 JavaScript 对象的更多信息...在下面的评论中:)
关于javascript - Javascript 中的逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10823663/