【发布时间】:2015-11-19 16:44:29
【问题描述】:
我正在编写一个 Javascript 代码,我需要在其中显示和隐藏 Web 的某些部分。我最终得到了这样的功能:
function hideBreakPanel() {
$('section#break-panel').addClass('hide');
}
function hideTimerPanel() {
$('section#timer-panel').addClass('hide');
}
function showBreakPanel() {
resetInputValues();
$('section#break-panel').removeClass('hide');
}
function showTimerPanel() {
resetInputValues();
$('section#timer-panel').removeClass('hide');
}
我的问题与代码质量和重构有关。什么时候最好有像这样的简单函数或直接调用 Javascript/jQuery 函数?我认为最后一种方法的性能更好,但在这种情况下性能不是问题,因为它是一个非常简单的站点。
【问题讨论】:
标签: javascript jquery coding-style refactoring