// jQuery 无new 创建对象套路 (function(g,undefined){ var foo = function(){ return new foo.fn.init(); }; foo.prototype = { saySth: function(){ console.log("say something"); }, init: function(){ console.log("inited"); return this; } }; foo.fn = foo.prototype; foo.fn.init.prototype = foo.fn; // 关键点 window.foo = foo; })(window); var o = foo(); o.saySth(); // 输出say something
jQuery无new创建对象原理
猜你喜欢
转载自www.cnblogs.com/macliu/p/11970406.html
今日推荐
周排行