현재 페이지에서 사용되는 하나의 큰 외부 자바 스크립트 파일이 있습니다. 내가 아약스 탭을 사용하여로드 된 다른 섹션을 가지고 있기 때문에 현재 자체 호출 함수에서 코드를 래핑하므로 다른 외부 js 파일과의 충돌을 피하기를 원합니다.자바 스크립트 파일을 작은 조각으로 구성하는 방법은 무엇입니까?
파일의 코드는 다음과 같이 구성되어 있습니다. plannerTab 네임 스페이스 내부의 일부 코드를 더 작은 파일로 분할하고 싶지만 여전히 네임 스페이스에 포함 시키십시오.
어떻게하면됩니까? 아니면 다른 접근 방식을 권장합니까? 감사!
// Document Ready
$(function()
{
// initializes table
plannerTab.plannerTable.init();
});
var plannerTab = (function()
{
// All the code for the page is in here. I would like to extract sections
// from in here and put them into their own external files while still keeping
// the namespacing
}();
업데이트
가 어떻게 작은 외부 JS 파일로 plannerTab 변수 내에서 부품을 분리 할 수, 그들이 plannerTab 네임 스페이스의 일부임을 여전히 유지? 아래의 작은 예. (구글)이 예에서
// Scope: plannerTab.config - Would like to store configuartion into a separate file
var config = {
selectors: {
tableId: '#plannerTable',
addTaskId: '#AddTask',
editTaskSelector: '#plannerTable .edit',
dateFilterSelector: '#plannerTable_TimeFilter li',
deleteTaskClass: '.delete',
searchFilter: '#plannerTable_filter',
selectedDateFilter: 'selected-dateFilter',
taskCellSelector: '#plannerTable .task-col',
taskClass: '.taskId'
},
urls: {
addTaskFormURL: '/Planner/Planner/LoadAddTaskForm',
editTaskFormURL: '/Planner/Planner/LoadEditTaskForm',
deleteTaskURL: '/Planner/Planner/DeleteTask',
getTasksByDateRangeURL: '/Planner/Planner/GetTasksByDateRange',
viewTaskURL: '/Planner/Planner/ViewTask'
}
};
개발 또는 배포 용이성입니까? HTTP 요청을 줄이기 위해 하나의 파일을 유지할 것을 제안합니다. –