
249
Chapter 10_
모듈형 자바스크립트 디자인 패턴
pluginExtension
.
js
// 코어 모듈 확장
(function (name, definition) {
var theModule = definition(),
hasDefine = typeof define === "function",
hasExports = typeof module !== "undefined" && module.exports;
if (hasDefine) { // AMD 모듈
define(theModule);
} else if (hasExports) { // Node.js 모듈
module.exports = theModule; // Node.js 로 모듈 정의
} else {
// 기본 네임스페이스나 전역 객체에 할당
// 플랫 파일(flat-file)형태나 전역 모듈 확장을 고려
var obj = null,
namespaces,
scope;
obj = null;
namespaces = name.split(".");
scope = this.jQuery || this.ender || this.$ || this;
for (var i = 0; i < namespaces.length; i++) {
var packageName = namespaces[i];
if (obj ...