结合以下功能有什么好处吗?
window.onload = function() {
if (localStorage.getItem("txt")) {
textarea.value = localStorage.getItem("txt");
changeDocTitle(localStorage.getItem("filename"));
isModified = true;
} else {
changeDocTitle(untitled);
}
};
function newNote() {
if (!isModified || dontSave()) {
textarea.value = "";
changeDocTitle(untitled);
}
textarea.focus();
}
组合后会是这样的:
window.onload = function() {
if (localStorage.getItem("txt")) {
newNote(localStorage.getItem("txt"), localStorage.getItem("filename"));
} else {
newNote();
}
};
function newNote(txt, filename) {
if (!isModified || dontSave()) {
textarea.value = txt || "";
changeDocTitle(filename || untitled);
if (textarea.value) {
isModified = true;
}
}
textarea.focus();
}
- 我也会
newNote()
用键盘快捷键调用这个函数..
两者有什么区别,有什么理由更喜欢其中一个吗?