這是一個擴展函數,須要初期加載的時候加載到適當的位置。函數
具體函數體以下:spa
$.namespace = function() { var a=arguments, o=null, i, j, d; for (i=0; i<a.length; i=i+1) { d=a[i].split("."); o=window; for (j=0; j<d.length; j=j+1) { o[d[j]]=o[d[j]] || {}; o=o[d[j]]; } } return o; };
使用的時候這樣寫,能夠避免一長串的對象賦值:code
$.namespace('system.user'); $.system.user.funcA = function(){ }