====== Javascript Namespace 생성 ====== namespace를 구분하여 자동으로 생성해준다. 이미 namespace가 존재할 경우에는 기존 객체를 바로 리턴한다. From [[http://www.aladin.co.kr/shop/wproduct.aspx?ISBN=8966260152|JavaScript Patterns]] 참고 : namespace는 사용금지 예약어이다. 되도록 다른 함수명으로 바꾸도록 하라. var MYAPP = MYAPP || {}; MYAPP.namespace = function(ns_string) { var parts = ns_string.split('.'), parent = MYAPP, i; if (parts[0] === "MYAPP") { parts = parts.slice(1); } for (i = 0; i < parts.length; i += 1) { if (typeof parent[parts[i]] === "undefined") { parent[parts[i]] = {}; } parent = parent[parts[i]]; } return parent; }; MYAPP.namespace("hello.world"); console.log(typeof MYAPP.hello.world); // object console.log(typeof MYAPP.hello.something); // undefined