<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>
Run Code Online (Sandbox Code Playgroud)
在上面的脚本中,我注意到:
container: $('#contact'),
这是一种声明变量的方法吗?执行以下操作会破坏脚本:
var container = $('#contact');
另外,init函数和容器变量之后的逗号是什么(如果它是变量)?
这样你就可以声明一个对象:
var contactForm = {
// properties:
property1 : value,
property2 : value,
property3 : value,
// methods:
method1 : function() {
// ...
},
method2 : function() {
// ...
}
};
Run Code Online (Sandbox Code Playgroud)
您可以在MDN中找到有关JavaScript对象的更多信息...以及下面的评论:)
| 归档时间: |
|
| 查看次数: |
238 次 |
| 最近记录: |