(function() {
	if (!window.project) {
		window.project = {};
	}
	window.project = {
		init: function() {
			alert("test");
		},
		show: function() {
			alert("test2");
		}

	};  
})();

  调用:project.init();
自己的修改

(function() {
	if (!window.project) {
		window.project = {};
	}
	window.project = {
		init: function() {
			alert("test");
		},
		show: function() {
			alert("test2");
		}

	};  
})(jQuery);

elfinder插件就是这么封装的。地址:
https://github.com/Studio-42/elFinder /////////////////////////////////////////////////////////////////////////////

function Range() {}
Range.prototype = {
	init: function() {
		alert("XXX");
	},
	show: function() {
		alert("YYY");
	}
};

function RangeChildren() {}
RangeChildren.prototype = Range.prototype;
RangeChildren.prototype.add = function() {
	alert("ADD");
};

调用:

var rc = new RangeChildren();
rc.add();
rc.show();
//工厂方式:封装函数
function test(name) {
    var obj = new Object();
        obj.name = name;
        obj.sayName = function () {
            alert(this.name);
        };
        //抛出
    return obj;
}
var p1 = test('小明');
p1.sayName();
var p2 = test('小王');
p2.sayName()

可参考其它的封装方法

原文地址:封装属于自己的JS
封装自己的js库(一)—仿照JQuery

Ebook 学习经验 Java Android Python JavaScript jQuery PHP Ruby-Jekyll Ubuntu CSS VPS elFinder 数据库 正则表达式