//一.把参数当作私有变量使用 (function (a, b) { //把参数当作私有变量使用,省略了var,也节省了行数 console.log(b) //undefined,所有未赋值的变量均为undefined })(window); //二.把参数作为参数使用 var obj_init = function (b, d, f) { //1.定义初始对象 var m = {}, v = {},e = {}; m = { //初始对象m }; v = { //初始对象v }; e = { //初始对象e }; //2.合并对象 jQuery.extend(m, b); jQuery.extend(v, d); jQuery.extend(e, f); //3.返回对象 return { model: m, view: v, events: e } } function ObjCall_Fn(f) { f = f || {}; //4.调用对象 var e = obj_init(f.model, f.view, f.events), c = e.model, b = e.view, d = e.events; //5.返回对象 return { add:function(){ return e.model.id; }, model: c, view: b, events: d } } //6.最后调用对象 var fn = ObjCall_Fn({ model: { id:100 }, view:{ }, events:{ } }); var ad = fn.add(); //fn.……; console.log(ad) //结果:100